Manipulate string in datatable column

Hi, In a data table I have a column where every row has a string formatted like this:

Received Monday 13-08-2023 08:32

I need the date only in this format: 13/08/2023.

I am now using a For each activity looping thru all rows in the data table, and I am removing “Received Monday” in one step, the time in a second step, and replacing the - (hyphen" in the data in a third step.

Can I do all this in one step (Meaning all necessary code in one activity in stead of 3)?

@wwls
row(“DateColumn”) = DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(row(“DateColumn”).ToString, “\d{2}-\d{2}-\d{4} \d{2}:\d{2}”).Value, “dd-MM-yyyy HH:mm”, CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

Hi @wwls

Try this in assign activity:

dt.AsEnumerable().ToList().ForEach(Sub(row)
    row.SetField("DateColumn", DateTime.ParseExact(
        System.Text.RegularExpressions.Regex.Match(row.Field(Of String)("DateColumn"), "\d+.\d+.\d+").Value,
        "dd-MM-yyyy",
        System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy"))
End Sub)

Hope it helps.

HI @wwls
Yes it will possible to do all in single step …
you can try with this way it will replaces in single step instead of three steps…!

str_variable=System.Text.RegularExpressions.Regex.Match(“Received Monday 13-08-2023 08:32”,“\d{2}[-\/]\d{2}[-\/]\d{4}”).Value.Replace(“-”,“/”)


output
image
Refer:CurrentRow(“Date”).ToString.Split(" “c)(2).replace(”-“,”/")

Can aslo try with this:In Assign Activity
System.Text.RegularExpressions.Regex.Match(CurrentRow(“Date”).ToString,“\d{2}-\d{2}-\d{4}”).ToString.Replace(“-”,“/”)

Thank you very much for your help!

1 Like

Thank you very much!

Thanks for your help!

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