Remove everything after first comma in an entire column of a datatable without for each

Hi everyone,

My requirement is to remove everything after the occurrence of the first comma in an entire column of a datatable. Please find the input and expected output below. My data table is huge and hence I cannot use for each loop. Please provide a code to do the same.

image

Thanks

Hello @ammohan

You can use Read Range to read the excel and then use Output datatable to convert to string. The use Text to columns or Generate Datatable acitvity.

Thanks

Hi Rahul,

I basically want to use invoke code to remove everything characters that come after the first comma for the entire column through an invoke code. The data table I have is huge with 76k records.

Thanks,
Amrutha

@ammohan ,
Please find the below code and use in invoke activity

DT.asenumerable.Tolist.Foreach(Sub(r) r(“Input”)=r(“Input”).tostring.split(","c).first.tostring).Copytodatatable

1 Like

@ammohan

Use split operation you will get output, Please find the below example

Ex: Input is a variable
Input =“12344, 87907”

  Syntax - Input.toString.split(",".ToCharArray)(0) 

Using this syntax you will get Output as 12344

Thanks
Varun

Hi @muhamed_fasil

I am getting the following error while using the code in invoke code.

Can you please help me to resolve it?

@ammohan ,
Please provide the datatable variable direction as inOut in the arguments of invoke activity

@muhamed_fasil Yes, I have given it as in/out. But still facing the same issue.

Hi @muhamed_fasil ,

I had to remove the .copytodatatable() part from the code and it worked.

Thanks!

1 Like

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