Replace a (n-1) character with another character using linq query

Hi

i have a datatable with contains currency column that needs to be validated and remove the ‘.’ and replace with ‘,’ as above stated, is there any linq query to do that. Instead of iterating and using regex to to the same?

I would like to replace the word as following, input is a string

input datatable

Amount
40.25
112.45
4.208.56
1.115.689.78
4,893.56
8,456,789,52

Output datatable

Amount
40.25
112.45
4,208.56
11,15,689.78
4,893.56
8,456,789.52

Thank you

1 Like

Hey @Naga_Abhishek_Reddy_Chepp

Core Linq Query

//Iterating through actual table
dt_Amount.AsEnumerable.Select(Function(row) _
//Adding rows to output table cloned from actual table
	dt_AmountOp.Rows.Add(
        //Forming a new string array & Converting amount column string value to char array
	New String(row("Amount").ToString.ToCharArray.Select(Function(c, index) _
                //If the char is a symbol prior to last 3 digits it will replaced by comma else by a dot
		If(index < row("Amount").ToString.Length-3, If(c.ToString.IsNumeric, c, ","c), If(c.ToString.IsNumeric, c, "."c))
	).ToArray) _
	)
).CopyToDataTable

Input

nmnithinkrishna_UiPath

Output

nmnithinkrishna_UiPath

Source code

nmnithinkrishna_DataTableColumnFormatUpdate.zip (2.5 KB)

Hope this helps.

Thanks
#nK