How to use the trim, split, substring, remove

activities

#1

Hi All:

I’m a beginner for UiPath. When I searched “how to remove a part of string”, there were lots of ways to achieve the result I found. Trim, slip, substring, remove,replace, etc. Actually, I know none of them. So could you please tell me how to use them or where I can find the introduction for them.
Thanks in advanced !:grin:


#2

You’ll be using string manipulation a LOT, so it’s wise to get acquinted with it :slight_smile:

Trim: removes leading or trailing spaces from a trim, or any other character (you can specify that as a parameter)
Substring: takes a part of the string, starting at your preferred index and then going for an x amount of characters. For example, if you have a string “Hello World” and you just want “Hello”, you’d work with: yourString.Substring(0, 5)
Remove: basically works the opposite way of substring. Where in substring you specify the part you want to keep, in remove you specify the part you want to get rid of.
Replace: replaces a part of the string with another string.

And I don’t know Slip, I don’t think that’s part of Visual Basic, the language UiPath uses.

For more info, visit the Microsoft Documentation on Visual Basic. And of course practise a lot, that’s the best way to get to know it.

https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/keywords/string-manipulation-summary
https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/strings/index


#3

Thanks you very much ! It’s very useful !


#4

Sorry, not “slip”, but “Split”
I am confused about the “split”, how to use split? Prefer a example for introduce.
Thanks in advanced !


#5

@Harvey You can check out with the following link for split


#6

Thanks @indra, but could you tell the function of the “toCharArray” ?


#7

Hello @Harvey, the delimiters must be in Array of Characters format, so if you only have one delimiter (like " "), you need to convert it to Array of Characters.

str1 = str1.Split(" “.ToCharArray) is the same as
str1 = str1.Split({” "c})


#8

The ‘Split’ method will split your string into an array of substrings. As a parameter you can pass in the character to split the string on. For example, if you pass in a space (’ '), the string will be split at every occurence of a space. In UiPath you can pass it as followes: str.Split(" "c)

You can also pass in an array of characters, like indra did. In that case it will split the string between the characters in the array. In this case it retrieves all the words between the spaces. He then selects the first word in the array (‘km’) by calling the index 0.

You can find more info here:


#9

Thanks ! :grinning:


#10

Thank you !:thinking::slightly_smiling_face: