Split on caps

How do i split a variable by caps? Example: JohnDeere β†’ John Deere?


Please check below thread for your reference.

1 Like

Hi @anon53238024

Better use regular expressions ex ([A-Z][a-z]*)
Refer below query

Hello @anon53238024,

You will find the answer here. In the solution they refer to Regex.Replace() , ensure you use System.Text.RegularExpressions.Regex.Replace() in UiPath.


This will give you the array after splitting the entire string into substrings after splitting with capital letter, so you can get them individually.


else if you want the first string give it as



Use an assign activity accepting an String variable and expression system.Text.RegularExpressions.Regex.Split(dummy,β€œ(?<!^)(?=[A-Z])”) where dummy is the string variable which holds your input string.
Please find the attached built sequence for easier usage
Dummy.xaml (4.9 KB)

Here in this β€œ0” represents the first element and 1 represents the second and so on…


1 Like

Thank you!

1 Like

Sometimes there will be names that are not two names combined. Ex only John.
I use:
System.Text.RegularExpressions.Regex.Split(str,β€œ(?<!^)(?=[A-Z])”)(0) to get the first item,

System.Text.RegularExpressions.Regex.Split(str,β€œ(?<!^)(?=[A-Z])”)(1) to get the second item.

If i only have a name that is not a combination of two names, an error will occur. How do i take this into account?

Better to assign the entire values to a string array after splitting using a assign statement like

strArray = System.Text.RegularExpressions.Regex.Split(str,β€œ(?<!^)(?=[A-Z])”)

where you will get the length of the array whether you have only one or two. Using that, you can loop through the values using for each and then you can continue with the next flow.

Else try catch is another option


How do i get the length? When i try to β€œwrite line” the results it is just returning β€œSystem.String”

if strArray is your array, you will get the length as strArray.Length and if you want to use it in write line, then strArray.Length.ToString as write line supports only strings


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