Split string and keep each character in a datatable

I have a string-“a-b-c;d-e;f-g-h-i”.
I have to split the string and keep each character row wise in a data table like this-

a b c
d e
f g h i

Hi @ydash999
Try this appraoch

  1. Build a datatable dt1 using Build datatable activity

  2. store the input string in a variable strinput

  3. Now use the assign actiivty to store the splitted output of strinput with delimiter as ; like below

arrRows= Split(strinput,“;”)

  1. loop through each item in arrRows ,

inside the loop do the following:

a. use add datarow to add a row to datatable dt1 with arrayrow parameter as Split(item.ToString,“-”)

where item is each element in arrRows

After the loop, use write range to write the dt1 to excel

You can see the required result.

Let me know if you have any questions :slight_smile:

Thanks & Regards,
Nived N

1 Like

Hi @ydash999 ,

Maybe you could also Check with Generate Datatable Activity.

1 Like

in column separator i only saw the given characters, i didnt try inputing the “-”, so was confused. now solved. thanks bro!

2 Likes

i tried this method, but output was not correct.each row system.string is showing in each row

out1.xlsx (8.3 KB)
stringtoDt.xaml (9.0 KB)
check if any problem and send the solution if u got it. thankss!

bro is there any other method like using string manipulation that we can try this?

@ydash999 ,

Maybe we could try ahead with Regex or the method provided by @NIVED_NAMBIAR . We do see multiple Steps but it will be effective when we have disturbances in the data, and if required to correct it.

But if your formatting is simple then it shouldn’t be a Problem with Generate Datatable Activity. With this activity, we could do it quickly with 1 Step unlike other methods where we would have to use Either a Linq or use Add Data Row to add rows to a Created Datatable which would have more than 1 Step.

Let us know if you are facing any issue with Generate Datatable Activity and maybe then we can provide a more refined solution.

1 Like

i already got solution with generate dt activity, but curious to know if any other way it can be possible.thankss!

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