How to divide String

Hello,

I am having a data like this inside the column name code,. here i want to split the first 3 and 2 charecters and put in 1st column and (-) should be remove and the remaining text should be placed in the next column name Name below is my sample screen shot

image

i need the output like below screenshot…

image

Thanks,
Suresh.

2 Likes

Use string.split("-"c) @suresh_kumar4
And assign to array of string variable and you can use foreach to iterate in the loop ang get the value or just pass the index and you will get the value

cheers

1 Like

Thanks, @pattyricarte,

can you please send me the sample.xaml file… because i am new to uipath…

if i use this one string.split("-"c) how can i get the code and name separatly… in the excel sheet??

Thanks,
Suresh.

hi @suresh_kumar4

try the below logic.
dt will a data table from read excel.

 for each row in dt
     {
       row("CODE")= row("CODE").split(cchar("-"))(0)
        row("Name")= row("CODE").split(cchar("-"))(1)
}

Regards
Ajay

@suresh_kumar4

1.use excel application scope and read range to read excel file and save output as dt .
2.Then use for each row and pass dt variable.
3.Inside for each row assign,

Str1=row(“Code”).ToString.Split("-“c)(0)
Str2=row(“Code”).ToString.Split(”-"c)(1)

4.After that use assign activity.
row(0)=Str1
row(1)=Str2

5.Then use write range activity to write dt.

image
image

My apologies @suresh_kumar4 yet i can send xaml for you im replying thru mobile.

Later i will

Thanx

1 Like

Thanks@monika…

I tried what you sent me…
but i am getting this error

Assign: Index was outside the bounds of the array.

Thanks,
Suresh.

@suresh_kumar4

check your code in assign activity…instead of row(1) you can use row(“ColumnName”)

1 Like

@suresh_kumar4 Is it possible to share your excel file so it will be useful to prepare xaml file

hi @suresh_kumar4
You use for each row to read excel file and add row activity in add row activity use this {row(“CODE”).Split("-“c).GetValue(0).ToString,row(“CODE”).Split(”-"c)…GetValue(1).ToString} and write it in the same excel

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.