How to manipulate a part of string: Split, Trim, Substring, Replace, Remove, Left, Right

Hi,
if you are a beginner in the world of automation and would like to know how you can manipulate text based on the solutions available in the VB.NET code and using REGEX (regular expressions) then you are in the right place.

In the topic below, you will learn how to easily extract data from any part of the search text using various methods.

The topic includes solution examples with descriptions and graphics to better understand the topic for functions such as:

  • Split
  • Substring
  • Left
  • Right
  • Replace
  • Remove
  • Trim, LTrim, RTrim
  • TrimStart
  • TrimEnd
  • Regex.Replace

I had prepared a workflow file with examples and Excel file with an explanation of how you can manipulate a part of string in variables. Examples are for RPA Dev Rookies.

Examples_Split_Trim_Substring_Remove_Left_Right.xaml (30.8 KB)
ENG Split Trim Substring Left Right Replace Remove.xlsx (26.3 KB)
POL Operacje na zmiennych Split Trim Substring Left Right Replace Remove.xlsx (26.2 KB)

Split, Double Split, Trim, Substring, Replace, Remove, Left, Left+Substring, Right, Right+Substring

Let’s get started:

SPLIT
Spit divides the text into parts:
For: String on the part = (0): left, (1): right
For: String [.] on value of strings
Example 1
Split takes a part of text to ‘Array of strings’ - after “:” and saves it in memory of Variable type String[.]
Variable name = text
Variable type = Generic Value
New Variable name = new_text
Variable type = Array of Strings (String[.])
text = Hello:World:Its:Me
Assign:
new_text = Split(text,":")
Write Line:
new_text(3)
Variable ‘new_text’ contains now array of 4 strings
(0) = Hello
(1) = World
(2) = Its
(3) = Me
Result (Write Line) : Me

Example 2
Split takes a part to ‘Array of character’ - after " " (c = .ToCharArray)
Variable name = text
Variable type = Generic Value
New Variable name = new_text
Variable type = Array of Strings (String[.])
text = Hello World Its Me
Assign:
new_text = text.Split(" ".ToCharArray)
Write Line:
new_text(2)
Variable ‘new_text’ contains now array of 4 characters
(0) = Hello
(1) = World
(2) = Its
(3) = Me
Result (Write Line) : Its

Example 3
Holding the result after the Split operation in a variable with the type ‘String’
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = Hello World Its Me
Assign:
new_text = text.Split(" "c)(2).ToString
Write Line:
new_text
Result (Write Line) : Its

Example 4 Double SPLIT
The first Split divides the text after the phrase “: W” and leaves the part to the right (1)
Second Split divides the left text after the first “:” and leaves what is left (0)
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = Hello:World:Its:Me
Assign:
new_text = Split((Split(text,":W")(1).ToString),":")(0).ToString
Write Line:
new_text
Result (Write Line) : orld

Example 5 Double SPLIT
The first Split divides the text into the phrase “: M” and leaves a part to the left (0)
Second Split divides the left text after the first “o:” and leaves what is on the right (1)
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = Hello:World:Its:Me
Assign:
new_text = Split((Split(text,":M")(0).ToString),"o:")(1).ToString
Write Line:
new_text
Result (Write Line) : World:Its

SUBSTRING
Example 1
Takes content 5 characters from the first character from the left (0)
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = Hello World Its Me
Assign:
new_text = text.Substring(0, 5)
Write Line:
new_text
Result (Write Line) : Hello

Example 2
Takes content 6 characters from the fourth character from the left (4)
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = Hello World Its Me
Assign:
new_text = text.Substring(4, 6)
Write Line:
new_text
Result (Write Line) : o Worl

Example 3
Takes contents of 3 characters from the end
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = Hello World Its Me
Assign:
new_text = text.Substring(text.Length -3)
Write Line:
new_text
Result (Write Line) : " Me"

TRIM, LTRIM, RTRIM
Trim: function to strip (deletes) the leading and trailing spaces from a string variable.
LTrim: function to strip (deletes) leading spaces from a string variable.
RTrim: function to strip (deletes) trailing spaces from a string variable.
Example 1
The value of ‘text’ contains “” to show that there are spaces in the text
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = " Hello World Its Me "
Assign:
new_text = text.Trim
Or
new_text = Trim(text)
Or
new_text = RTrim(text), or LTrim(text)
Write Line:
new_text
Result (Write Line) : “Hello World Its Me”

REPLACE
Replace changes the specified character type to another
Example 1
The value of ‘text’ contains “” to show that there are spaces in the text
*Change " " (spaces) to `" "` (pipe)*
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = " Hello World Its Me "
Assign:
new_text = `text.Replace(" ", "
Write Line:
new_text
Result (Write Line) :

REMOVE
Remove removes the text that we describe in the logic (inverse to SUBSTRING)
Example 1
Deleting content 5 characters from the first character from the left (0)
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = Hello World Its Me
Assign:
new_text = text.Remove(0,5)
Write Line:
new_text
Result (Write Line) : World Its Me

LEFT
Retrieves the text from the variable from LEFT
Example 1
Gets the content 7 characters from the left
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = Hello World Its Me
Assign:
new_text = Left(text, 7)
Write Line:
new_text
Result (Write Line) : Hello W

LEFT + SUBSTRING
Gets the text from the variable counting from the LEFT of what is left after trimming by SUBSTRING
Example 1
Retrieves the content of 3 characters from the left counting from ‘cropped text to 5 characters’ counted from the 7th character of the phrase ‘text’
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = HelloWorldItsMe
Assign:
new_text = Left(text.Substring(7,5), 3)
Write Line:
new_text
Result (Write Line) : rld

RIGHT
Retrieves the text from the variable from RIGHT
Example 1
Gets the content 7 characters from the right
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = HelloWorldItsMe
Assign:
new_text = Right(text, 7)
Write Line:
new_text
Result (Write Line) : ldItsMe

RIGHT + SUBSTRING
Retrieves the text from the variable counting from the RIGHT from what is left after trimming by SUBSTRING
Example 1
Gets the content ‘3 characters from the right’ from ‘cropped text to 6 characters’ ‘from the beginning (0)’
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = HelloWorldItsMe
Assign:
new_text = Right(text.Substring(0,6), 3)
Write Line:
new_text
Result (Write Line) : loW

TrimSTART
TrimStart removes all leading occurrences
Example 1
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = “00000ABC123000”
Assign:
new_text = text.TrimStart("0"c)
Write Line:
new_text
Result (Write Line) : “ABC123000”

Example 2
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = “00000ABC”
Assign:
new_text = text.TrimStart({"0"c, "A"c})
Write Line:
new_text
Result (Write Line) : “BC”
TrimEND
TrimEnd removes all trailing occurrences
Example 1
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = “00000ABC123000”
Assign:
new_text = text.TrimEnd("0"c)
Write Line:
new_text
Result (Write Line) : “00000ABC123”

Example 2
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = “00000ABC-”
Assign:
new_text = text.TrimEnd({"-"c, "C"c})
Write Line:
new_text
Result (Write Line) : “00000AB”
REGEX.Replace
Example 1
Replace any non-word character to nothing (remove)
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = “000 abc 111-ABC@!&”
Assign:
new_text = System.Text.RegularExpressions.Regex.Replace(text, "\W","")
Write Line:
new_text
Result (Write Line) : “000abc111”

Example 2
Replace any word character (include digits) to nothing (remove)
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = “abc 123 !@#$%^&*()_”
Assign:
new_text = System.Text.RegularExpressions.Regex.Replace(text, "\w","")
Write Line:
new_text
Result (Write Line) : " !@#$%^&*()_"

Example 3
Replace any digit character to nothing (remove)
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = “A1B2C3D4E5F67890GH”
Assign:
new_text = System.Text.RegularExpressions.Regex.Replace(text, "\d","")
Write Line:
new_text
Result (Write Line) : “ABCDEFGH”

Example 4
Replace any non-digit character to nothing (remove)
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = “A1B2C3D4E5F67890GH”
Assign:
new_text = System.Text.RegularExpressions.Regex.Replace(text, "\D","")
Write Line:
new_text
Result (Write Line) : “123456789”

Example 5
Replace specific set of characters like: “A”, “^”, “!” to nothing (remove)
` ` pipe is separator in regex (alternative)
\ back slash is use to escape special character in regex (^ in regex set begining of expression)
Variable name = text
Variable type = String
New Variable name = new_text
Variable type = String
text = “A1B^C3D^E5F!!89^GH”
Assign:
new_text = `System.Text.RegularExpressions.Regex.Replace(text, "A
Write Line:
new_text
Result (Write Line) : “1BC3DE5F89GH”

Examples_Split_Trim_Substring_Remove_Left_Right.xaml (30.8 KB) ENG Split Trim Substring Left Right Replace Remove.xlsx (26.3 KB) POL Operacje na zmiennych Split Trim Substring Left Right Replace Remove.xlsx (26.2 KB)

219 Likes
How to use the trim, split, substring, remove
Replace of multiple strings
String manipulation with constant string length
.net functions
Split a variable longer than 20 characters
Extract part of string before the comma "," and put in a variable. Then extract string after dash "-" and put in variable
Need a regular expression to extract the date part
Split value after 3rd special character
Add 1 Character to String
How to append data in string variable + uipath
String Operations Instr
Parsing the string
How to get part of the string
How to Remove " from a string of Variables
String manipulations help needed
Regex help tutorial MEGAPOST – Making your first Regex post, Reusable Regex Patterns, Regex Troubleshooting, Sample Workflow and more
Concatenation
How to and where to learn Vb.Net Expressions/functions
How to remove unwanted text in string
Need to check if the string is corrent dosent matter capital or simple
Find Exact word
ISSUE in SPLIT VALUE
How to split a random text containing numbers and print the last 9 digits
Please help to split string
Text exist - eliminate whitespace importance
Establishing a 'Quick Start' Library for Learners
How to Remove the space in between the lines
How to extract from array of json object to excel sheet?
How to split a sentence with different data
Get text after first space
Split spacific text from e mail body
Assign: Conversion from string "Rs.82,900.04" to type 'Integer' is not valid
Regex to fetch Project information
Extract values from String
Extract first letter of every word of a given string
Application Bug [String manipulation]
How to Get First Letter of every word in a String
Get part of a String and text before it
How to use string manipulation
Split text from string?
Writing .tsv excel file?
How to convert once cell data in multiple cells
Split File Name of Excel File to create sheet name
Get data in a proper format from html , innerhtml
How to get From date And To date From Read file
Add folder in current directory
How to delete row in word document
Add spaces before and after a specific character
Compare text then remove text with rules applied
How to read pdf contains multiple pages
Overriding Ctrl+F in forums posts
Specific body email
Convert String Array to Integer Array UiPath
If the last caractere is a space then delete it
HOW compare two columns in excel
Send Outlook Mail message body
Get the value before a character
How to extract email id from a string without using regex
I have text file and I have around 100 strings separated by , . I need to select a particular string and need to remove all strings before that particular string
Scraping Partial Text From Row
DT split cell question
Is there a way to remove words before "-" from a specific column in excel?
Header Split
Replace character at specific index
About Split Method result
String manipulation 1
String not recognised as valid date time
Peforms the same action based on number of rows inside the web page
String Operation to extract Email Id from a String
Get a specific value from string
Spiltting a Data Dictionary
Split string and remove last 2
Extract specific text form txt file
How to select first instance only where it matches a condition - from Data Scraping
Not finding correct selection
Conver to Collection (ToArray, ToCharArray, ToList, ToDictionary ...)
Unable to split a array of string
How to split string variable
Automating Text extraction of strings between two special characters in microsoft word to excel Columns
UiPath의 초급자의 학습방법
Decrease int value
Split String File Name
How to get specific texts from the file
Splitting a string
Your XAML Solutions for most common issues (WIKI POST, anyone can edit)
Split Synatx error
String Manipulation12
Extract date time from string of PDF file
PDF Automation extracting text
How can I remove parts of a variable
Data Manipulation in Studio: String Manipulation
Help with string manipulation
Get info from PDF
CTRL+F "Find" not working like normal?
I want to separate these 3 sentences. Please help me. Thanks in advance
Get certain line numbers from string
Extract substring from directory path between symbols
Getting particular string from the text
If Array or List Contains name Remove
Get Substring from Multiple Line String
Hi EveryOne I need some help, I have the number which i have given in the below screen. I want the result for this. Please solve this
String Manipulation-Replace
Zero detector at variable start
How to replace string by index position
How to execute a list of commands in cmd
Get information out of a String using Keywords and Comma, having amounts
How to spit string in notepad
Split string that has new line and a lot of spaces in it

Hi
@Adrian_Star

Welcome to uipath community
That’s cool
great job…keep going
Cheers

6 Likes

could you help me get the date from this string?

First Name Last Name\r\n2 September 2019\r\nPowered by TCPDF (www.tcpdf.org)

without using like the set numbers but rather the word “Powered” as the length of the entire string changes

Hello, You can use:

A) Split by char
Where:
Variable:
text = eg. Generic Value
new_text = String (Array of strings)

Input:
text = JOHN SMITH\r\n2 September 2019\r\nPowered by TCPDF (www.tcpdf.org)

Logic:

new_text = Split(text," "c)
  1. Exampe
    Write Line = new_text(0) + " " + Split(new_text(1),"\r\n2")(0)

Output: JOHN SMITH

  1. Example

    Write Line = new_text(0) + " " + Split(new_text(1),"\r\n2")(0) + " " + new_text(2) + " " + Split(new_text(3),"\r\n")(0)

Output: JOHN SMITH September 2019


B) Split by Split in String

  1. Example
    To Get FirstName and Last Name You can use also:

Variable:
text = eg. Generic Value
new_text = String

Logic:

new_text = Split(text,"\r\n2")(0).ToString

Write Line: new_text

Output: JOHN SMITH

  1. Example
    Additionally to Get “Month Date”

Logic:

new_text = Split((Split(text,"\r\n2 ")(1).ToString),"\r\n")(0).ToString

Write Line: new_text

Output: September 2019

12 Likes

@Adrian_Star Great post! Was very helpful to solve my string splitting.

2 Likes

Hi! I have a problem with string manipulation. How do you get the string value after the text ‘Dependent Verification -’

Example: Dependent Verification -Approved

I need to get the any string that comes after the ‘-’

Thanks!

Use split method like this
Split(str_input,”-“)(1).ToString

Cheers @caduque

7 Likes

Hi @Palaniyappan

Actually the value ‘Dependent Verification -’ is a row value.

So my code would be Split(row(5).ToString,”-“)(1).ToString ?

1 Like

Yah Correct
Cheers @caduque

2 Likes

Hi @Adrian_Star

I moved your post to the #news:faq section, it’s great!

I suppose it could only use some better formatting, currently I think you simply copy pasted the text from other source and it looks a bit awkward :smiley:

5 Likes

Hey, I’m putting graphics for a better understanding of the subject.

Moved to first entry.

13 Likes

Does anyone know how to remove the symbol " in a text? I tried

str_paymentpartner.Replace(“”“,”")

but doesn’t seems to work :sweat_smile: :weary:

1 Like

@Nasya.Idris Please check below one.

str_paymentpartner.Replace(“”“”,“”)

3 Likes

You can use logic:

output = System.Text.RegularExpressions.Regex.Replace(your_String, "[^\w\.@-]","")

or

output = System.Text.RegularExpressions.Regex.Replace(yourString, "[^\w\.@-]"," ")

regex

Or read this post:
Replace (regex) problems

9 Likes

Thank you!

4 Likes

bravo and I hope this gets added to some of the official documentation/ reference in academy. bump for visibility

6 Likes

Amazing! This is as if good for documentation in UiPath. I wish the UiPath Academy would also add some in-depth tutorials like this one for addressing specific functionalities in their courses. Great job @Adrian_Star!

7 Likes

Você esta de Parabéns!!!

2 Likes

This is amazing! Thank you so much for this.

3 Likes

Thank you very much man. You definitely simplified everything.

3 Likes