How to determine the activity name for a input to be string?


#1

I need to find out a activity to determine string input


#2

Well you mean “string that means all letters” or ?


#3

Yes…I meant…any string…it may be a sentence, or a phrase or even a few letters…


#4

Hi,
Only letters:
Regex.IsMatch(input, @"^[a-zA-Z]+$");

Only letters and numbers:
Regex.IsMatch(input, @"^[a-zA-Z0-9]+$");

Only letters, numbers and underscore:
Regex.IsMatch(input, @"^[a-zA-Z0-9_]+$");


Set regular expression condition
#5

I need to check it without using regex


#6

Well i am just assuming if you mean "string that means all letters

your_variable_storing_input_box_output.ToString.All(function© Char.IsLetter©).ToString

// well if string is like “RandomeString” it will return True because all are letters but if you will try like this “test 12” it will return false.

Regards…!!
Aksh


#7

thnks a lt…let me try once


#8

It`s working for say “working” but returning false for “its working”

Is there any options?


#9

Where can I put this function directly e.g. Regex.IsMatch(input, @"^[a-zA-Z]+$")
I inserted an activity Is Match where I could type your Regex. And after that an If activity checked the output. Is there an easier way?

Thank you!


#10

try this:

var.All(function(x) char.IsLetter(x) or x = " " or x = "." or x =",").ToString


#11

In assign statement.

bool var = Regex.IsMatch(input, @"^[a-zA-Z]+$")

See its properties in the right side having a “patter property” just enter their like this “^[a-zA-Z]+$”.

Well both way it will return output in boolean so you can direct use it in if statement Regex.IsMatch(input, “^[a-zA-Z]+$”)

Regards…!!
Aksh


#12

Do you have any idea what could be the problem with the below Assign statement (testResult is bool variable)?

Could it be the problem that the System.Text.RegularExpressions namespace is not on Imports panel (as it is in Visual Studio C#)

Thank you!


#13

Yes might be jusr import it if you have not otherwise use like this System.Text.RegularExpressions.Regex.IsMatch(input, “^[a-zA-Z]+$”)

but it is better to import the namespace.

and please remove this @ from that pattern.


#14

Thank you! Last question about regex. The @ sign stands for what? In the above examples somewhere it was used, but in my project UiPath doesn’t accept @ sign at all.


#15

thnaks a ton…it works


#16

Hey @UiJules

@ is a verbatim string literal.
Verbatim strings start with @ symbol and end with the matching quote. The C# compiler understand this type of string as verbatim string. the @ symbol tells the string constructor to ignore escape characters and line breaks.

Well for your understanding:

variable_1=@“c:\user\aksh\Desktop\abc.xlsx”;

is same as:

variable_1=“c:\user\aksh\Desktop\abc.xlsx”;

To get it more about it, check it out this link. Will be helpful for you: Link

Regards…!!
Aksh


#17

Oh, I see the point. In case of Regex, do you use the verbatim string to the Regex pattern or to the string that will be verified by the Regex.

Anyway, It was used in the below example, but it throw an error for me.
bool var = Regex.IsMatch(input, @"^[a-zA-Z]+$")

Thank you again for your replies.


#18

VB string literals are very similar to C-style verbatim ones, so there is no special symbol to indicate this; you just use regular strings and don’t have to escape backslashes. By the way, the “IsMatch” function is also available as a UiPath activity, along with Match and Replace. I prefer to use these because they allow you to easily modify the regex options, like case sensitivity and single line/multi line modes.