Removing Special Characters from CSV file and write data back to CSV file

Hi i am trying to remove all possible special characters from CSV file (Description and Amount column) and retain the other data back to the new file or same file. Kindly help.

test

1 Like

Hi
welcome to uipath community
–use READ CSV FILE activity and pass the file path of csv file as input and get the output with a variable of type datatable named dt
–now use a OUTPUT DATATABLE activity and mention the input as dt and get the output with variable of type string named str_dt
–then use a assign activity like this
str_dt = System.Text.RegularExpressions.Regex.Match(str_dt.ToString,"[^$–*]+").ToString

–then use a GENERATE DATATABLE activty and pass the string variable as inptu and get the outptu with a variable of type datatable named finaldt
–now use WRITE CSV FILE activity and pass finaldt as input and form a csv

Cheers @veerishu

Hi,

Hope the following helps you.

Value property of each Assign activity are the following.
System.Text.RegularExpressions.Regex.Replace(row("Description").ToString,"[^.\w ]","")

System.Text.RegularExpressions.Regex.Replace(row("Amount").ToString,"[^.\w ]","")

Regards,

3 Likes

@Palaniyappan: Appreciate quick response. Thanks a lot.

The Solution is generating in one single column (As shown in the screenshot). I need the data
written in different columns like shown in my very fist post and for all the data. May be need to use for each row activity. Kindly help

execution1

1 Like

Is comma mentioned as delimiter in generate datatable activity
Kindly check that once pls
@veerishu

1 Like

@Yoichi Thanks a lot for the reply.

This helps me. However, Could you kindly help me alter the below expression to remove even the unwanted spaces in between

System.Text.RegularExpressions.Regex.Replace(row(“Description”).ToString,"[^.\w ]","")

image

1 Like

Hi,
It is a late reply. But it will be useful to some one.

Here is a package called BalaReva.EasyText . It has an activity called “Find & Replace All”. Using this , you can remove all special charactors.

Regards
Balamurugan.S

Hi,

If you want to remove all spaces, the following will work.

System.Text.RegularExpressions.Regex.Replace(row("Description").ToString,"[^.\w]","")

IF you want to remove space at the beginning / end of the sentence and replace 2 or more spaces to a space, the following steps will work.

strData = System.Text.RegularExpressions.Regex.Replace(row("Description").ToString,"[^.\w ]","").Trim
row("Description") = System.Text.RegularExpressions.Regex.Replace(strData," {2,}"," ")

Regards,

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