For each row that has text - how to code

I have a data table like this:
[
abc
"
abc
]

I would like to use a for each to say use the row that contain text but unsure how to configure that in the for each - I think I will need an IF statement but unsure how to edit code to say if row has text

try
For each currentrow in yourDataTable
if string.isnullorempty(currentrow(0).toString) then
no text
else
text
end if

You can also use a filter datatable activity to filter out all the empties. Then you know for sure each row (if any) have text.

1 Like

The row will not be empty - it will contain characters that are not text like “”

Is there a way of saying if row contains this character then delete that row

then replace the if condituon with a regex validation taht matches the values you do want to keep.

Thank you! One of the characters I need to keep in the data table

How would I configure the for each to say : for each row that does not contain "

I have tried this:

Cheers

Hi @E.T.S

For Each Row in dt
    If String.IsNullOrEmpty(row("ColumnName").ToString) = False
        // Do something with the row that contains text
        // You can use row("ColumnName").ToString to access the text in the row
    End If

Hope it helps!!

1 Like

@E.T.S

You can try with this in if activity

System.text.regularexpression.regex.ismatch(currentrow(“columnname”).tostring,“[a-zA-z0-9]+”)

Gives you boolean output

If there is any text gives true otherwise it will give false

Cheers

Hi

Hope the below steps would help you resolve this in one single expression without looping which save your bot execution time

dt = dt.AsEnumerable.Where(Function(r) System.Text.RegularExpressions.Regex.IsMatch(r(“ColumnName”).ToString(),“[A-Z]+|[a-z]+|[0-9]+”)).CopyToDataTable

This will give only the rows with column having having text in it
Any specific characters if coming will remove it as you were asking here

You can use the same inside a FOR EACH ROW activity if you want it inside a loop

Use a if condition and mention like this

System.Text.RegularExpressions.Regex.IsMatch(r(“ColumnName”).ToString(),“[A-Z]+|[a-z]+|[0-9]+”)

If yes it goes to THEN block or to ELSE

Hope this helps

Cheers @E.T.S

1 Like

The dt = dt.AsEnumerable.Where(Function(r) System.Text.RegularExpressions.Regex.IsMatch(r(“ColumnName”).ToString(),“[A-Z]+|[a-z]+|[0-9]+”)).CopyToDataTable code works wonderfully thank you!

1 Like

This specific example: How would I configure the for each to say : for each row that does not contain "
if not currentrow(0).toString.contains(“”“”) '<-- 4 times double quote, or use chr(34) instead of the 4x quotes)

1 Like

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