How to Get First n Characters of a String in UiPath?

Get first n characters of a string using UiPath Studio. In this demo, we will get first two characters of a string and display on the console output.

Add a new Assign activity and initialize the string you want to manipulate. I have used message variable of string datatype.

Assign string variable in UiPath studio

Add another Assign activity and initialize the integer variable with the value (This value represents, how many characters you want from the string).

Initialize an Integer variable in UiPath

Add a Write Line activity to print the first n characters on the console output. We will make use of substring function.

Syntax: String.Substring(startIndex As Integer, length As Integer) As String
Expression: message.Substring(0, n)
Write Line activity to print the first 2 characters of a string in UiPath

Below is what the complete flow looks like.

Complete UiPath flow to Get First n Characters of a String in UiPath

Console Output

Output console output showing the first 2 characters of a string in UiPath

Thank you All!!! Hope you find this useful.


Up ↑

%d bloggers like this: