Remove digits from string

Hey everyone,

I have a string which I generated from a datacolumn by
“String.Join(Environment.NewLine,(From r In DT Select r.item(“Column Name”)))”

so the data inside the string is like below:

123,123123
122,123123
151,412312
151,34334
232,32422

etc.

What ı need is I need to make the numbers as:

123,12
122,12
151,41
151,34
232,32

any idea? or code that could work on this?
Thank you

Hi @jntrk ,

Try this.
Test.xaml (5.4 KB)

@jntrk - Please check this…

this deletes everything after the first row

system.Text.RegularExpressions.Regex.Replace(str, “” , “”)

how is the code gona be?

My bad , I thought you want to capture it in for each row in loop.
Then you can use regex of @prasath17

Instead of replace you can pick the needed ones and write it to same column or to a new column(Based on your requirement, if you want to write it to back to excel)

system.Text.RegularExpressions.Regex.Match(Str,"\d+,\d{2}")

image

this happens when ı try to do

Str = system.Text.RegularExpressions.Regex.Match(Str,“\d+,\d{2}”)

Hi @Catalina_Rs ,

Can you try now.
Linq used -
(From d In DT.AsEnumerable
Let a = d(“A”).toString.Substring(0,d(“A”).toString.LastIndexOf(“,”) +3)
Let ra = New Object(){a}
Select dtOutput.Rows.Add(ra)).CopyToDataTable

Test.xaml (7.6 KB)

Output:

It should be …

Str = system.Text.RegularExpressions.Regex.Match(Str,"\d+,\d{2}").value

OR

Str = system.Text.RegularExpressions.Regex.Match(Str,"\d+,\d{2}").tostring

@jntrk On top of it you can also use regex if you are not comfortable with substring mentioned by @prasath17

(From d In DT.AsEnumerable
Let a = system.Text.RegularExpressions.Regex.Match(d(“A”).Tostring,“\d+,\d{2}”).value
Let ra = New Object(){a}
Select dtOutput.Rows.Add(ra)).CopyToDataTable
Test.xaml (7.7 KB)

I keep getting empty string as result

okay lets change something feeling like it would be easier do do.

Currently I have these things in datatable variable :

123,123123
122,123123
151,412312
151,34334
232,32422

now how can I change those to 123,12

you mean these are different rows right? or these strings are in the same cell??

Have you tried xaml that I have shared in previous comments, it already doing that.
Run it as it is and then utilize it in your code.

okay okay I have managed to make it work. Thank you both very much. The problem was on the regex its given “,” but firstly it was “.” i replaced it “,” so the code you gave was executing first and not been able to find the “,” that why I got empty rows.

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