Extract part of string before the comma "," and put in a variable. Then extract string after dash "-" and put in variable

I need to extract two parts of a string and put them in a variable. For example, my format is “lastname,firstname-1234”. I need to extract the last name and put it in a variable and then extract 1234 and put it in a variable.

1 Like

@path1
You can use the string split function.

Assuming your variable is called “myString” you can do:
myString.Split(","c).First to get lastname
myString.Split("-"c).Last to get 1234

","c is shorthand for ",".ToCharArray. The split function uses a character array, I prefer the c notation since it’s shorter.

Hi @path1

You can refer to the article below for your reference.

cheers :smiley:

Happy learning :smiley:

Hi
In addition to what others mentioned hope this would help you in this as well

If the above input is stored in a string variable named str_input
Then in ASSIGN activity

str_lastname = Split(str_input,”,”)(0).ToString.Trim

Similarly for that number

Str_number = Split(str_input,”-“)(1).ToString.Trim

Where both str_lastname and str_number is a variable of type string

Cheers @path1

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.