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

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):

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, “[1]+$”))
{
//Some activity.
}
else
{
}


  1. a-zA-Z0-9\x20 ↩︎

2 Likes

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…!

Hi,

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

Any sample special character which you want to exclude .

1 Like

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

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

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.

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.

1 Like