Data manipulation in a string

Hi Champs,

Just needed a help to make a condition, as my is not working perfectly.
consider a text :- 07_ANP_BMCC

Suppose this is a string, then i want to make a condition in which i want to check that the string starts with a numeric and has either a “Space” or a “_” after first two characters .

Thanks !!

@Palaniyappan can u help

1 Like

Hi
The condition be like this
If the string is stored in a variable named str_input then In IF condition

IsNumeric(str_input.ToString.SubString(0,2)) AND
str_input.ToString.SubString(2,1).Equals(“ “) OR str_input.ToString.SubString(2,1).Equals(“_”)

Cheers @Shikhar_Tandon

1 Like

This is a good candidate for Regex Match because it’s a nice consistent pattern you’re looking for.
You can use a condition like

Regex.Match(yourStringVariable, “^[0-9]{2}( |_)”).Success

in your If statement. This will give you a true value if the string matches your pattern, or false if it doesn’t.
If you want to learn more about the expression I’ve made a demo on regexr showing how it works.

1 Like

Thanks @Palaniyappan and @jfarnden for the reply. Was thinking if you can help me with a condition to check , a row variable is empty. I was using IsNothing(row(“text”).toString) and the particular cell is empty also then also this condition is returning nothing.
Please help

If the String is “” (blank/empty) technically it’s still something to the computer, so IsNothing doesn’t work great for strings like this. Check out IsNullOrWhiteSpace and IsNullOrEmpty, as i expect one of these will fit your scenario better.
IsNullOrEmpty will check for a null or an empty string ("").
IsNullOrWhitespace will also check if they have entered blank spaces like " ".

Usage is like

String.IsNullOrEmpty(yourStringVariable)

1 Like

You were almost done
The expression be like this in IF condition
String.IsNullOrEmpty(row(“text”).ToString.Trim)
If true it goes to THEN part which means the row has empty value in it or goes to ELSE part which means it has some value in it

Cheers @Shikhar_Tandon

1 Like