Can't find desired text in string

hi all,

I’m using the GetFullText activity and I get a string back of this type

“Standard\t\nplace1\t\nname surname\t\nplace2\t\nplace3”

I then try to read if the string contains “Standard place1” but when I write it simply like this with a space in between the bot doesn’t enter that if statement.

how can I approach this issue?

thanks

Hi @Dea_Pahumi

inputString = "Standard\t\nplace1\t\nname surname\t\nplace2\t\nplace3"
searchString = "Standard place1"

// Trim whitespace and line breaks
inputString = inputString.Replace("\t\n", " ").Trim
searchString = searchString.Trim

// Perform a case-insensitive comparison
If inputString.ToLower.Contains(searchString.ToLower)
    // Your code here if the condition is met
Else
    // Your code here if the condition is not met

Hope it helps!!

Hi @Dea_Pahumi

you can replace the string and then check with the if - activity with condition it will work sure

you can try like this…
str = “Standard\t\nplace1\t\nname surname\t\nplace2\t\nplace3”.Replace(“\t\n”," ")

you can give if condition like this

if = str.contains(“Standard place1”)

for the refernce you can see the screenshot

You can use Regex also
please try this


hope it helps
Usha

@Dea_Pahumi

StrGetFullTextInput.ToString.Contains(“Standard”) and StrGetFullTextInput.ToString.Contains(“place1”)

the string contains a tab and a new line, it is not physically written when I display the string in a message box it looks like this
Screenshot_2
so using Replace(“\t\n”," ") is not helping

Hi @Dea_Pahumi

strvariable.Split({Environment.NewLine},Stringsplitoptions.RemoveEmptyEntries)

This will give you the string in a single line

H!

You can try like this then, it will replace multiple lines to single line

str = Regex.Replace(str,“\r?\n”," ")

hope it may helpfull for you

when \t\n are copy pastes from e.g. debugging panels and representing a proper tab or line break we can use isMatch / Regex.Match for a defensive check:

grafik

strText = your Text
strPattern = "Standard[\s]*?place1"

myCheck | Boolean = System.Text.RegularExpressions.Regex.IsMatch(strText, strPattern)

[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

thank you @ppr this solved my case :smile:

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