Split dynamical string


#1

hi

actual str=“123-456-6789”

i need to split like this dynamically

str1="123"
str2="456"
str3=“6789”

if i add string
str=1234-2345-123

it should disp
str1="1234"
str2="2345"
str3=“123”

pls send me how to split and save it to another variables

tq


#2

@Venkatp,
Use Regex Match “\d”

Try the below link…
https://regex101.com/


#3

you can use Split –
example:
data.Split({"***"},stringsplitoptions.None).ToArray


#4

not working can you pls send xaml file


#5

One simple way is to use .Split using the character that’s consistent like the dash.

arrString = str.Split("-"c)

Then run that through a loop to extract each element and process.

For each str In arrString
Message Box str

EDIT:
Or instead just store each element directly without a loop, like,
str1 = arrString(0)
str2 = arrString(1)
str3 = arrString(2)


If the character can change other than a dash or if there are random alpha/special characters then you might consider using System.Text.RegularExpressions.Regex.Match( ) with a pattern

Hope that helps further.

Regards.


#6

@Venkatp

Hi vengat,
try this Main.xaml (13.3 KB)


#7

Hi, @Venkatp
Try this statement in Assign activity
variable=Regex.Matches(yourString,"\d+")
Before that you need to import System.Text.RegularExpression in import panel
Then in for each loop iterate the variable…
you can achieve that…
Regards,


#8

thank you all