Concatenate rows into single string


#1

Hi, I have a set of data that is structured as many rows in a single column within a data table that I need to concatenate into a single row, separated by a semicolon. What is the best way to do this in UiPath. Below is an example how the data is currently structure and how I need to re-structured:

Currently structured in data table:
123
456
745
459
154

How I need it restructured:
123;456;745;459;154

Thank you for your assistance!


How to print the first column from csv file in uipath
#2

string CommaRow=string.Join(",",dtSample.AsEnumerable().[Select](Function(s) s.Field(Of String)(“name”)).ToArray())


#3

Thanks for the reply. However I was not able to make it work. This is what I entered:

String CommaRow=String.Join(";",dtOpenCases.AsEnumerable().Select (“nCaseID”)).ToArray())

with dtOpenCases as the name of my data table and nCaseID as the name of the column I am referencing in the example above. UiPath is giving me an error under Row=String saying that it is expecting a period but when I replace the = with a period, I still receive the same error.


#4

Thiis doesn’t work for you in Assign? Copy Paste

string CommaRow=string.Join(",",dtOpenCases.AsEnumerable().[Select](Function(s) s.Field(Of String)(“nCaseID”)).ToArray())

CommaROw.xaml (5.9 KB)


Copying entire Column from Datatable
#5

The code in your example worked! I needed to add Function(s) before s.Field. Thank you!!


#6

Great example! Could you please help me extend it, so that output will come in quotes like “John”,“Jane”,“Albert”…etc.


Foreach loop output as array instead of string.join
#7

If above example is working for you then, this is one way to achieve your req.

chr(34)+string.Join(chr(34)+","+chr(34),dtOpenCases.AsEnumerable().Select(Function(s) s.Field(Of String)(“nCaseID”)).ToArray())+chr(34)

#8

Great, many thanks!


#9

by the way, is it .net notation? Maybe you could point to good resource with examples, I miss a lot not having solid .net background for making complex queries like this.


#10

Hi Vidhya,

I am trying to run the code but I am getting this error -

CommaROw has thrown an exception

Message: Unable to cast object of type ‘System.Double’ to type ‘System.String’.

Can you help pls?


#11

In above snippet, field is of type String. Try changing to “Of Double” in your example.

s.Field(Of String)(“nCaseID”))

Thanks,

Vinay


#12

Hi @Dharam_Prakash,

You probably just need to update where it says “s.Field(Of String)” to “s.Field(Of Double)”. That should take care of it.


#13

Thanks maan! Sorry got your name wrong.