Can you help me out in adding a try catch block In checking whether the expression contains special characters?

studio

#1

Scenario:

Steps to reproduce:

Current Behavior:

Expected Behavior:

Studio/Robot/Orchestrator Version:

Last stable behavior:
Last stable version:
OS Version:
Others if Relevant: (workflow, logs, .net version, service pack, etc):


#2

Hi,
Is there any specific requirement of Try/Catch, because its just 2 line code. :slight_smile:

String test_string = “tesintg#$234524@#”;

if (System.Text.RegularExpressions.Regex.IsMatch(test_string, “^[a-zA-Z0-9\x20]+$”))
{
//Some activity.
}
else
{
}


#3

If you could help me…How about using a try catch block until finding the exact expression works?


#4

Yes…w.r.t try catch if the expression contains special characters then is to perform a click operation…else the output in the message box…!


#5

Hi,

Referring to the above answer… Could you please guide me in another condition excluding a few special characters…?


#6

Any sample special character which you want to exclude .


#7

It would be a comma “,” or a single quote… please if you could help me in understanding the dynamic expressions written will be better…


#8

Since the name is separated by a comma…it needs to be excluded in the condition…so how about the condition to be framed?


#9

So you don’t need a try-catch, you need to remove special chars from a string, right?.
This will create a string containing only letters and whitespace from your OP variable (if it’s a string, if not, change OP to OP.ToString:

new String(OP.Where(Function(c) Char.IsLetter(c) OrElse Char.IsWhiteSpace(c)).ToArray)

PS. Also please don’t spam topics.


#10

But the expression that holds well only for few special characters like a single quote,is what i’m In need of…it would be better if you could help me in this…


#11

Create a variable Array(Of Char), f.e. named charsToOmit put default as {"'"c, "/"c}
This is your collection of characters you want to get rid of. The c is there to inform the workflow that it’s a Char instead of String
Now you can easily modify what you want to omit straight from the variables panel.

New code would be:
new String(OP.Where(Function(c) Not charsToOmit.Contains(c)).ToArray)
Which can be read as:
Create a new String from my OP string, but only from those chars not contained in charsToOmit.

Sample attached below.
BecauseWhyNot.xaml (4.8 KB)

IMHO this method will be more readable than trying to cope with Regex syntax, if you’re not already used to it.