Hello,
How do i split a variable by caps? Example: JohnDeere β John Deere?
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.
Regards,
Nithin
This will give you the array after splitting the entire string into substrings after splitting with capital letter, so you can get them individually.
System.Text.RegularExpressions.Regex.Split(str,β(?<!^)(?=[A-Z])β)
else if you want the first string give it as
System.Text.RegularExpressions.Regex.Split(str,β(?<!^)(?=[A-Z])β)(0)
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β¦
System.Text.RegularExpressions.Regex.Split(str,β(?<!^)(?=[A-Z])β)(0)
Thank you!
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,
and:
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.