Linq Get String after :

How do i achieve this by using Linq? The rows are unlimited in real situation so that’s why I’m resorting to Linq.

image

@arina
Inside for each row in data table
assign

System.Text.RegularExpressions.Regex.Match(currentrow(0).tostring,"([a-zA-Z]+)(\d+)").Groups(2).Value

Hi,

Can you try the following sample?

dt.AsEnumerable.ToList.ForEach(
Sub(r)
    r("Description")=System.Text.RegularExpressions.Regex.Match(r("Description").ToString,"(?<=:\s+).*$").Value
End Sub
)

Sample20221205-3.zip (8.7 KB)

Regards,

1 Like

Hi @Yoichi

  1. Use Read Range activity → Store it as DtRead

  2. Use For each row in data table activity

Note : In the LINQ it will also loop through Line by Line there is no difference

Inside the Loop

  1. Use Assign activity
CurrentRow("Description") = 
System.Text.RegularExpressions.Regex.Match(CurrentRow("Description").ToString,"\d*$").Tostring

Outside the Loop

  1. Use Write Range activity and Pass the DtRead as output

Regards
Gokul

Hi @arina,

What about this workflow

Input
image

Output
image

Workflow

Xaml
05.xaml (7.1 KB)

Code

(From row In dt.AsEnumerable
Let output = If(row(“Input”).ToString.Split(CChar(“:”)).count>1,row(“Input”).ToString.Split(CChar(“:”))(1).Trim,row(“Input”).ToString)
Select dt.Clone.Rows.Add(row(“Input”).ToString,output)).copytodatatable

Best,
Raj

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