Split does not take into account "the zeros"

Hi UiPath Community,

Im doing a split string on MRC-18300/12/000008 with the separator “/” ( split(0), split(1), split(2), )
Then im writing the result on a excel , my problem is split(2) on excel the zero are not taken into account, it’s writing 8 and I want 000008.

And if it’s MRC-18300/12/000099 i want on the excel 000099 not 99

Can anyone help, have an idea how to do it ?

Thanks in advance

1 Like

Fine
Use this expression to get the last value next to separator “/“
If the input is stored in a variable of type string named str_input

str_output = “‘“ +Split(str_input.ToString,”/“).Last().ToString.Trim

What this does is it will concatenate single quotes with the value so that the term is retained as a text which will keep 000 in front for sure

Cheers @tharuler

1 Like

@tharuler,

You need to change the datatype of that cell in the excel to “Text” from “general”

then you can use split like this StringVariable.Split(“/”,StringSplitOptions.None)

1 Like

Your problems is not Split function but Excel.
Excel interpret 000008 as number therefore removes any leading zero.
You should add ’ (single quote) in front to force Excel to interpret is as text

i.e. '000008

Cheers

2 Likes

the result is upload on a web app to search a folder, i can’t add a single quote, the rest of the process would no longer work

1 Like

Then fine we can directly mention this
.str_output = Split(str_input.ToString,”/“).Last().ToString.Trim

And still if that doesn’t work while typing did we try that manually whether it is accepting of typed

Or try with copy paste method
That is pass the variable str_output to SET TO CLIPBOARD activity
Then use SEND HOT KEY activity with key as ctrl+v
Which will paste the value from clipboard to that field

Cheers @tharuler

1 Like

sorry i didn’t quite understand, im not very good, im doing this right now


How can i apply this

1 Like

No problem
We can use this in a normal assign activity
str_output = Split(str_input.ToString,”/“).Last().ToString.Trim

Cheers @tharuler

1 Like

Then follow this proposal

1 Like

how when the excel file is created and filled automatically from a data table, and then excel is read to complete a serie of action on a web app

you can loop through that particular column and replace that part of string!

1 Like

is there a way to delete the single quote

thanks @Palaniyappan

1 Like

Remove that part alone buddy
Like this in assign activity

Cheers @tharuler

1 Like

thanks you’all robot master, you’re too kind

1 Like

Cheers @tharuler

Im back again robot master

Even with that, excel still don’t take into account the 0000, i need a way to force it

1

1 Like

Fine
If we are passing this value to any web page or any application then use this
str_output = Split(str_input.ToString,”/“).Last().ToString.Trim

Or

If we are trying to update this In a excel file we need to concatenate a single quote before like this
str_output = “‘“ + Split(str_input.ToString,”/“).Last().ToString.Trim

Cheers @tharuler

im passing it to an excel and then to a web page

so if i do that

i will have '00008
or i can use " '000000 " on my web page because of the single quote

and if i do

i wont have the zero on the excel and again the process will not work further on the web page

im kind of stuck

Fine let’s do one thing
If you can set that column as text in excel itself so that it will become as a template
And whenever data is added to that column it will have zero in it
And also we won’t.m face issue while passing that to web page

So use this alone as expression
str_output = Split(str_input.ToString,”/“).Last().ToString.Trim

But ensure that the column in excel is set to Text type this (making that as a template accepting zero in front)

Cheers @tharuler

1 Like