string position separated by comma

arkiboys 9,686 Reputation points

How is it possible whilst inside foreach, to get items from one position to another in a string?
For example:

variable v_mystring = 'addressxyz', 'addressuiuy', 'addressqqq', 'addresslklk', ...'address7uu'..., 'address93'
I would like to get item in position3 up to poition 87, looking at the above example it should give:
'addresslklk', 'address7uu' --> assuming in this example 'address7uu' is in position 87

Thank you

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,135 questions
0 comments No comments
{count} votes

Accepted answer
  1. Nasreen Akter 10,791 Reputation points

    Hi @arkiboys ,

    would you please try the following:

    @fr (take(skip(split(variables('v_mystring'),','),2),85),',')

    This expression will first convert the string to an array by splitting it --> then will skip first 2 items and take 85 items from that array --> and finally convert back the array to a string.

    Hope this helps. Thanks!

1 additional answer

Sort by: Most helpful
  1. ShaikMaheer-MSFT 38,326 Reputation points Microsoft Employee

    Hi @arkiboys ,

    Thank you for posting query in Microsoft Q&A Platform.

    What you mean when you say String positions? You mean position of characters in string? If yes, we can use substring() function.

    substring() function return characters from a string, starting from the specified position, or index. Index values start with the number 0.

    substring('hello world', 6, 5) this will return world as result.

    If you mean to take string between commas as position and then compiling substring of positioned strings, then you can consider using split() function to split string based on commas and then loop through string using ForEach activity and then form new desired substring accordingly.

    Hope this helps. Please let us know if any further queries.


    Please consider hitting Accept Answer. Accepted answers help community as well.

    0 comments No comments