How to use “Padleft” “Padright” ?— UIPATH

During the project design phase, we will examine the “Padleft” and “Padright” commands that we can use when we want to add a space to a “String” value in a Table or when we want to add a value in a “Char” structure.
I will make an example through a table. Suppose we need to enter a value in an application and the condition for the application is to start with “0” .
How can we add to our existing table values?
Let’s start by creating a simple table first. By creating a table variable named “ExDt” , I wrote numbers in the “String” structure in the “ID” column.

Let’s see how we can add in the “For Each Row in Data Table” Activity;
After entering our variable, we assign an “Assign” activity in “For Each Row in Data Table” .

We create and write a “String” variable named “ID”.
We write it in this syntax against it. If we look at the content;

row.item(“ID”).ToString.PadLeft(5, “0”c)

row.item(“ColomnName”).ToString” = The column element is taken by typing the column name.
.PadLeft or PadRight” = Right and Left, the position is specified.
(5, “0”c) = 5 — Adds according to how many digits it will be. (01234)
“0”c = “0” is the number to add. “c” stands for char.
Then let’s look at the result by adding “Message Box”.
Result;

image

image

So what would we do if we wanted to add spaces ?
row.item(“ID”).ToString.PadLeft(5)
The number to be added and the expression “char” should have been subtracted and written this way.

3 Likes