I want to know how to replace column B and column D with only numeric values.
E.g . Output for Column B is : 1 Output for Column D is : 6
7 23
396 9
The format is fixed only numeric values are dynamic.
I know how to replace single value : String.Replace(“abc”,“”)
But for multiple rows in excel for specific column I’m not able build the logic.
This query will first check in both ColumnB & ColumnD for a string for the presence of any numeric character, if so, it will extract the number & update the same in these columns.
(From row In dtTest.AsEnumerable()
Let filteredB = New String(row.Field(Of String)("B").Where(Function(c) Char.IsDigit(c)).ToArray())
Let filteredD = New String(row.Field(Of String)("D").Where(Function(c) Char.IsDigit(c)).ToArray())
Select dtTest.Clone().Rows.Add(row.Field(Of String)("A"), filteredB, row.Field(Of String)("C"), filteredD)).CopyToDataTable()
Replace “dtTest” with you datatable name and assign it to a datatable variable(Use the assign activity in UiPath, left side = variable(e.g. dtTestTest) and right side = Linq Statement above. I guess your columns are of type string.
Try it, may need some modification based on needs.
Keep in mind that the above statement only works for whole numbers
e.g. “abc 17” would turn out to “17”.
and “abc 17.1” would turn out to “171”.
This is a “ugly” way to take “.” and “,” in consideration(if a word contains “,” or “.” e.g. “ab,c 17” output = “,17”):
(From row In dtTest.AsEnumerable()
Let filteredB = New String(row.Field(Of String)("B").Where(Function(c) Char.IsDigit(c) OrElse c = "." OrElse c = "," ).ToArray())
Let filteredD = New String(row.Field(Of String)("D").Where(Function(c) Char.IsDigit(c) OrElse c = "." OrElse c = "," ).ToArray())
Select dtTest.Clone().Rows.Add(row.Field(Of String)("A"), filteredB, row.Field(Of String)("C"), filteredD)).CopyToDataTable()
There is also a posibility to use the “IsNumeric” function and other variants.