UiPath

Introduction to UiPath string checking with samples

In UiPath Studio development, there are many times when you need to check and determine strings.

In this article, we will show you how to check if a string contains null, empty, or blank space, or if it matches a specified string, with samples.

 

 Related Articles Learn the Creation Techniques f UiPath robotics creation with Udemy’s online courses that take it up a notch

This site was created by translating a blog created in Japanese into English using the DeepL translation.

Please forgive me if some of the English text is a little strange

Check if a string is null, empty, or blank-paced.

Check if the string is null or empty (IsNullorEmpty)

To check if a string is null or empty, use IsNullorEmpty.

 

Code to check if a variable of type String “str1” is null or empty

String.IsNullOrEmpty(str1)
  • First value in (): string to be checked

 

sea otter
sea otter
IsNullorEmpty is a function to determine if a given string is null or empty.

 

・Sample Process

 

・Execution result



F-pen
F-pen
If the target string is null or “”, then True is returned.

 

Check if the string is null, empty or white space (IsNullOrWhiteSpace)

To check if a string is null or empty, use IsNullOrWhiteSpace.

 

Code to check if a variable of type String “str1” is null or empty

String.IsNullOrWhiteSpace(str1)
  • First value in (): string to be checked

 

sea otter
sea otter
IsNullOrWhiteSpace is a function that determines if a given string is null, empty, or consists only of white space characters.

 

・Sample Process

 

・Execution result



F-pen
F-pen
Unlike IsNullorEmpty, IsNullOrWhiteSpace returns the character for white space as True.

 

 

Check if the string contains the specified string.

Check if the string contains the specified string (Contains).

Use Contains to check if the string contains the specified string.

 

Code to check if the String variable “str1” contains “ab”.

str1.contains("ab")
  • First value in (): string to search

 

sea otter
sea otter
Contains is a function that determines if a given string exists within this string.

 

・Sample Process

 

・Execution result

 

・Other samples and execution results
Left side of // is code, right side of // is output result

str1 = "abc123"
str1.contains("a")   //True
str1.contains("b")   //True
str1.contains("ab")   //True
str1.contains("z")   //False
str1.contains("az")   //False
str1.contains("a1")   //False
str1.contains("c1")   //True
str1.contains("123")  //True
str1.contains("1234")  //False

 

 

Check if the string matches the specified string (Equals)

Use Equals to determine if the string matches the specified string.

 

Code to check if the variable “str1” of type String matches “abc123”.

str1.Equals("abc123")
  • The first value in (): the specified string to search.

 

sea otter
sea otter
Equals is a function to determine if the specified strings are identical.

 

・Sample Process

 

・Execution result

 

・Other samples and execution results
Left side of // is code, right side of // is output result

str1 = "abc123"
str1.Equals("abc123")    //True
str1.Equals("abc")      //False
str1.Equals("12")      //False
str1.Equals("abc12345")     //False
str1.Equals("ABC123")    //False
str1.Equals("ABC123", StringComparison.CurrentCultureIgnoreCase)    //True

 

F-pen
F-pen
Equals is case-sensitive by default.
sea otter
sea otter
By adding StringComparison.CurrentCultureIgnoreCase, you can do a case-insensitive check.

 

 

Check if the string matches the specified string forward (StartsWith).

Use StartsWith to determine if the string starts with the specified string.

 

Code to check if a variable of type String “str1” is a forward match for “ab”.

str1.StartsWith("ab")
  • The first value in (): the specified string to search.

 

F-pen
F-pen
StartsWith is a function to determine if the first string and the specified string are identical.

 

・Sample Process

 

・Execution result

 

・Other samples and execution results
Left side of // is code, right side of // is output result

str1 = "abc123"
str1.StartsWith("a")      //True
str1.StartsWith("b")      //False
str1.StartsWith("z")      //False
str1.StartsWith("abc12")     //True
str1.StartsWith("ab123")     //True
str1.StartsWith("ab1234")     //False
str1.StartsWith("ABC")     //False
str1.StartsWith("ABC",StringComparison.CurrentCultureIgnoreCase)    //True

 

sea otter
sea otter
By adding StringComparison.CurrentCultureIgnoreCase, you can do a case-insensitive check.

 

 

Check if the string matches the specified string backward (EndsWith)

Use EndsWith to determine if the string ends with the specified string.

 

Code to check if a variable of type String “str1” is backward matched with “23”.

str1.EndsWith("23")
  • The first value in (): the specified string to search.

 

sea otter
sea otter
EndsWithは、後方の文字列と指定した文字列が同一かを判定する関数だよ

 

・Sample Process

 

・Execution result

 

 

・Other samples and execution results
Left side of // is code, right side of // is output result

str1 = "abc123"
str1.EndsWith("3")      //True
str1.EndsWith("2")      //False
str1.EndsWith("23")     //True
str1.EndsWith("ab")     //False
str1.EndsWith("abc123")    //True
str1.EndsWith("C123")     //False
str1.EndsWith("C123", StringComparison.CurrentCultureIgnoreCase)  //True
sea otter
sea otter
By adding StringComparison.CurrentCultureIgnoreCase, you can do a case-insensitive check.

 

 

summary

  • Use IsNullorEmpty and IsNullOrWhiteSpace to check if the string is null, empty, or blank space.
  • To check if the string contains the specified string, use Contains, Equals, StartsWith, and EndsWith.
  • Since IsNullorEmpty, Contains, and Equals are the most frequently used, please learn them first.

Back to Table of Contents

 

 Related Articles Learn the Creation Techniques f UiPath robotics creation with Udemy’s online courses that take it up a notch

 same category UiPath

 

The operator of this blog, F-penIT blog