Regex to replace multiple comma with single space

regex
Hi Guys,
can you please help me to build the regex code to replace multiple comma with single space.
can we use replace activity for this?
and this action should be done in excel datatable inside for loop for every row
requesting you to help me on the below code
row(“HP Faults”) = System.Text.RegularExpressions.Regex.Replace(row(“HP Faults”),“{,+}”," ").ToString.Trim
Regards,
Naveen

Hi @naveenkumarr

In the CSV file the row has an empty value. So you find a lot of Comma in the excel file.

Regards
Gokul

Those aren’t extra commas. @naveenkumarr

They’re blank columns.

If you take them out, you’ll break the format of the CSV file.

Regards
Gokul

@Gokul001
FYI, those are commas.
i appended multiple column values in a single columns and it is appended by , comma
Dim row As DataRow
For Each row In io_datatable.Rows
row(“HP Faults”) = row(“ALLCASSETTESFAULTED”).ToString+“,”+row(“CARDREADERPROB”).ToString+“,”+row(“CASHHANDLERPROB”).ToString+“,”+row(“CASHOUTPROBLEM”).ToString+“,”+row(“COMMDOWN”).ToString+“,”+row(“ENCRYPTORPROBLEM”).ToString+“,”+row(“INSUPERVISORY”).ToString+“,”+row(“JOURNALPRINTERPROB”).ToString+“,”+row(“STATECLOSED”).ToString+“,” +row(“RECEPTPRINTER”).ToString+“,”+row(“REJECTBINFATAL”).ToString
Next
so for the column which doesn’t have value, it is taking only comma. Hope you got my point

Regex.Replace(STR, " {,}", " ")

ps: please import System.Text.RegularExpressions

1 Like

Hi @naveenkumarr ,

Could you let us know what is the End Expected Output ? Maybe we can correct this in the code itself as it is the source where the extra commas are getting added.

Let us know what is that you are trying to perform. If you still want to stick to the use of Regex to perform replace on the extra commas as an added operation, we could do the same.

Hello @naveenkumarr
Try this

row(“HP Faults”) = System.Text.RegularExpressions.Regex.Replace(row(“HP Faults”).tostring,“[,]+”," ").ToString.Trim

image

1 Like

image

Hi @naveenkumarr use this regex to replace multiple comma to single space

System.Text.RegularExpressions.Regex.Replace(Var,“[,]+”," ")

Thanks everyone for the response, and thanks @Gokul_Jayakumar for the solution provided :slight_smile:
Regards,
Naveen Kumar

@naveenkumarr
Pleasure is mine

Happy Automation :wink:

Regards
Gokul Jai

1 Like

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