Split String based on Underscore


I have a Long filename as string that I want to split.

Filename: C:\User\JUHA\Desktop\eAkte\Dokument\04_Muller, Nadine_Resume.pdf

Out of this filename, I want to extract “04” and “Muller, Nadine”.

Thanks for your help.

@juliahansen91 you can give like this input variable.Split({"","_"}) this will give you output as array of string say outarray.
-now to get your values outarray(6) for 04
-outarray(7) for Muller, Nadine

@juliahansen91 Assign v1= v1.Split("_".ToCharArray)(1)

@juliahansen91 First you should use an assign activity and save the filename to a string variable. Assign filename = Path.GetFileNameWithoutExtension("C:\User\JUHA\Desktop\eAkte\Dokument\04_Muller, Nadine_Resume.pdf"). This will return the string so it is only 04_Muller, Nadine_Resume

Next, you can split the string by underscore. Assign splitStr (this is an array of string variable) = Strings.Split(filename,"_")

Now you have an array of 3 strings. splitStr(0) = “04” ; splitStr(1) = Muller, Nadine ; and splitStr(2) = Resume

Thank you Dave.
I managed to extract the information from the filename.
When I run the process, everything is working fine.
However, at the end of the process, I get following error message:


Do you know what I am doing wrong?

@juliahansen91 you can try this
Assign V1= C:\User\JUHA\Desktop\eAkte\Dokument\04_Muller, Nadine_Resume.pdf

Assign V1= v1.Split("_".ToCharArray)(1)
Assign V1= V1.Split(“.”.ToCharArray)(0)

Now V1 will have Muller, Nadine

That error means you tried to reference an index outside the array. So if an array contained 4 items, then that would mean if you tried to reference array(4) or higher, then it would throw that error. The index starts at 0, so array(0), array(1), array(2), and array(3) are all valid for an array containing 4 items.