Remove line (row) nr. n from multiple rows in data table column cell

Hi, I am extracting data from a website regularly, and saving it to a data table. Sometimes the data in one or more columns will have multiple rows/lines in a cell, like this:

ABCD
1234
5678

How can I delete one or two of these rows and keep the third? (or delete two and keep one for that matter)

@wwls

If you need the last line always then use for loop to iterate over the rows of the column

And then use assign inside currentrow("ColumnName") = currentrow("ColumnName").ToString.Trim.Split({Environment.NewLine},Stringsplitoptions l.None).Last

cheers

Hi @wwls ,

In invoke code activity, use the below code by keeping dt as in/out argument:

For Each row As DataRow In dt.Rows
If row("ColumnName").tostring.Split(environment.NewLine.ToCharArray).Count>1 Then
 row("ColumnName")=row("ColumnName").tostring.Split(environment.NewLine.ToCharArray).last.tostring
End If
Next

Regards,

Hi @wwls

You can use the “Split” method to split the string into an array of lines. You can specify the delimiter as a newline character, like this: -

myString.Split(Environment.NewLine.ToCharArray(),StringSplitOptions.RemoveEmptyEntries)

Use the “RemoveAt” method of the array to remove the line(s) you want to delete. For example, to remove the second line: myArray.RemoveAt(1)

Thanks!!