# Working With Strings - UiPath

**URL:** <https://forum.uipath.com/t/working-with-strings-uipath/395993>\
**Category:** RPA Discussions\
**Tags:** coding, general\
**Created:** [February 1, 2022, 5:58pm UTC](https://forum.uipath.com/t/working-with-strings-uipath/395993 "2022-02-01T17:58:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lokesh.Bysani](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lokesh.bysani/32/263520_2.png) [@Lokesh.Bysani](https://forum.uipath.com/u/Lokesh.Bysani)\
**Post date:** [February 1, 2022, 5:58pm UTC](https://forum.uipath.com/t/working-with-strings-uipath/395993/1 "2022-02-01T17:58:18Z")

</div>

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)`

---

<div class="post-metadata">

**Author:** ![lakshman](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lakshman/32/523490_2.png) [@lakshman](https://forum.uipath.com/u/lakshman)\
**Post date:** [February 1, 2022, 7:11pm UTC](https://forum.uipath.com/t/working-with-strings-uipath/395993/2 "2022-02-01T19:11:23Z")

</div>

@Lokesh.Bysani

Welcome to our UiPath community.

It’s very helpful for new beginners.

> [@Lokesh.Bysani](#):
>
> - **TrimStart:** Removes the spaces at the end of the string - `str_CompanyA.TrimStart`
> - **TrimEnd:** Removes spaces at start of the string - `str_CompanyA.TrimEnd`

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

---

<div class="post-metadata">

**Author:** ![Lokesh.Bysani](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lokesh.bysani/32/263520_2.png) [@Lokesh.Bysani](https://forum.uipath.com/u/Lokesh.Bysani)\
**Post date:** [February 2, 2022, 5:10am UTC](https://forum.uipath.com/t/working-with-strings-uipath/395993/3 "2022-02-02T05:10:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![samj](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/samj/32/251450_2.png) [@samj](https://forum.uipath.com/u/samj)\
**Post date:** [February 3, 2022, 4:10am UTC](https://forum.uipath.com/t/working-with-strings-uipath/395993/4 "2022-02-03T04:10:38Z")

</div>

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)`
