Working With Strings - UiPath

Hi Everyone,

We often work with Strings and manipulation of strings when working on projects. I would like to cover the most frequently used functions here and hope it would be helpful for you.

With the help of these functions, we can avoid activities for simple functions.

Below two variables were used to cover the different functions.

str_CompanyA = " This is Company : A "
str_CompanyB = “This is Company: B”

  1. Trim: Removes leading and trailing spaces from the string - str_CompanyA.trim
  2. TrimStart: Removes the spaces at the start of the string - str_CompanyA.TrimStart
  3. TrimEnd: Removes spaces at the end of the string - str_CompanyA.TrimEnd
  4. ToUpper: Converts all characters in string to upper case - str_CompanyA.ToUpper
  5. ToLower: Converts all characters in string to lower case - str_CompanyA.ToLower
  6. Length: Returns total number of characters present in the string - str_CompanyA.length
  7. len: Returns total number of characters present in the string - len(str_CompanyA)
  8. Left(n): Returns First n characters from string -Left(str_CompanyA,5)
  9. Right(n): Returns last n characters from string - Right(str_CompanyA,5)
  10. StrReverse: Reverse the given string - StrReverse(str_CompanyA)
  11. IndexOf(‘a’): Returns the position of first occurance of the specified text str_CompanyA.IndexOf('a')
  12. LastIndexOf(‘a’): Returns the position of last occurance of specified text str_CompanyA.LastIndexOf('a')
  13. Split a string . Two different ways split(str_CompanyA,",") & str_CompanyA.Split(","c)
  14. Split based on new line. Try with vbCrLf & vbCr based on scenario. str_CompanyA.Split(vbLf,StringSplitOptions.RemoveEmptyEntries)
  15. Equals: Compare two strings. Output is boolean str_CompantA.Equals(str_CompanyB)
  16. StrComp: Compares two strings. Returns 0 if both strings are equal. Else -1 StrComp(str_CompanyA,str_CompanyB)
  17. Replace(“a”,“b”): Replace all occurances of a with b in a given string str_CompanyA.Replace("i","I")
  18. Remove(1,5): returns the string with 5 characters removed starting from index 1 str_CompanyA.Remove(1,5)
  19. Insert(index,string): Inserts a specified string or character in the specified index str_CompanyA.Insert(1,"Hello")
  20. IsNullOrEmpty: Returns true if string is null or empty else returns false string.IsNullOrEmpty(str_CompanyA)
  21. IsNullOrWhiteSpace: Returns true if string is null or whitespace else returns false String.IsNullOrWhiteSpace(str_CompanyA)
  22. Concat: Joins two or more strings string.Concat(str_CompanyA," - ",str_CompanyB)
  23. Another way to Join strings str_CompanyA+" - "+str_CompanyB
  24. Another way to Join strings str_CompanyA&" - "&str_CompanyB
  25. Convert secure string to string
    new System.Net.NetworkCredential(string.Empty,"Your Secure String").Password
  26. Convert String to secure string
    (new System.Net.NetworkCredential(string.Empty, str_CompanyA)).SecurePassword
  27. Convert string to “Proper” or “Title” case
    StrConv(str_CompanyA,VbStrConv.ProperCase)
  28. contains(“a”): Returns true if specified text present in the string else false str_CompanyA.contains("Hello")
  29. String.Format: Build a string based on a template - String.Format("The active user is {0} and their favourite food is {1}.", strName, strFavFood)
  30. Strings.Join: Joins an array of strings with the given delimiter (to reverse a split string or summarize a list) - Strings.Join({ "array", "of", "strings" }, ", ")
  31. If you ever need a " character in your strings, you need to double them up - String.Format("The user typed ""{0}"".", strInput)
  32. str_CompanyA.Split({ vbCrLf, vbLf }, StringSplitOptions.RemoveEmptyEntries)
7 Likes

@Lokesh.Bysani

Welcome to our UiPath community.

It’s very helpful for new beginners.

It should be vice-versa. Can you modify it.

Thank you for the feedback Lakshman. Much appreciated. I made the necessary corrections.

1 Like

Might also be useful to add the following:

  • String.Format: Build a string based on a template - String.Format("The active user is {0} and their favourite food is {1}.", strName, strFavFood)
  • Strings.Join: Joins an array of strings with the given delimiter (to reverse a split string or summarize a list) - Strings.Join({ "array", "of", "strings" }, ", ")
  • DateTime#ToString: Converts a date to a string with the given format - DateTime.Now.ToString("yyyy-MM-dd")

If you ever need a " character in your strings, you need to double them up - String.Format("The user typed ""{0}"".", strInput)

Also if you need to deal with both vbCrLf and vbLf, you can pass them in as an array to Split: str_CompanyA.Split({ vbCrLf, vbLf }, StringSplitOptions.RemoveEmptyEntries)

2 Likes