What is a String?

You are currently viewing What is a String?

Overview

A String is a finite sequence of text characters. A string can include letters, numbers, words, phrases, spaces, or even symbols. 

For example, both the word “Car” and the phrase “I drove the car” are both considered strings. Even “1234” is considered a string as long as it is surrounded by quotation marks.

In UiPath, strings must be enclosed in quotation marks (“ “) so that the data can be recognized as a string and not a number, variable name, or other code.

Strings are used everywhere in UiPath and are the most commonly used data type. Some are their uses consist of properties of activities, file names, and even logging.

What can you do with Strings?

Below are some great examples of the use of Strings:

  • Working with File and Folders paths
  • Type Into Activities
  • Logging

Commonly Used Properties

The following are some commonly used properties for Strings. A property is a characteristic or attribute of an object (i.e. String). To learn more about properties, click here

For all examples below, we will be using the following String variable, stringVar, which has been assigned as “Hello World”.

Chars(Integer) - Gets the character at a specified index.

Example Property Example Return Return Type
"Hello".Chars(2)
l
Char
"Hello".Chars(0)
H
Char
stringVar.Chars(6)
W
Char

Length - Gets the number of characters in a string.

Example Property Example Return Return Type
"Hello".Length
5
Integer (Int32)
stringVar.Length
11
Integer (Int32)

Commonly Used Methods

The following are some commonly used methods for Strings. Methods are actions that objects (i.e. String) can perform. To learn more about methods, click here

For all examples below, we will be using the following String variable, stringVar, which has been assigned as “Hello World”.

Comparison Methods

Compare(String,String) - Compares 2 Strings. Returns 0 if they match and -1 or 1 if they don't match. Does not ignore case.

Example Method Example Return Return Type
String.Compare("Hello","Hello")
0
Integer (Int32)
String.Compare("Hello","World")
-1
Integer (Int32)
String.Compare(stringVar,"Hello World")
0
Integer (Int32)
String.Compare(stringVar,"World")
-1
Integer (Int32)

Compare(String,String,Boolean) - Compares 2 Strings ignoring case if Boolean is set as True. Returns 0 if they match and either -1 or 1 if not.

Example Method Example Return Return Type
String.Compare("Hello","hello",True)
0
Integer (Int32)
String.Compare("Hello","hello",False)
1
Integer (Int32)
String.Compare(stringVar,"Hello World",True)
0
Integer (Int32)
String.Compare(stringVar,"World",False)
-1
Integer (Int32)

CompareTo(String) - Compares a String to another String. Returns 0 if they match, and either -1 or 1 if not.

Example Method Example Return Return Type
"Hello".CompareTo("Hello")
0
Integer (Int32)
"Hello".CompareTo("Hi")
-1
Integer (Int32)
stringVar.CompareTo("Hello World")
0
Integer (Int32)
stringVar.CompareTo("Hi")
-1
Integer (Int32)

Contains(String) - Check if a string contains a specified string.

Example Method Example Return Return Type
"Hello".Contains("He")
True
Boolean
"Hello".Contains("Hi")
False
Boolean
stringVar.Contains("Wo")
True
Boolean

Contains(Char) - Check if a string contains a specified character.

Example Method Example Return Return Type
"Hello".Contains("H"c)
True
Boolean
"Hello".Contains("W"c)
False
Boolean
stringVar.Contains("W"c)
True
Boolean

EndsWith(String) - Check if a String ends with a specified string.

Example Method Example Return Return Type
"Hello".EndsWith("lo")
True
Boolean
"Hello".EndsWith("Wo")
False
Boolean
stringVar.EndsWith("World")
True
Boolean

EndsWith(Char) - Check if a String ends with a specified character.

Example Method Example Return Return Type
"Hello".EndsWith("o"c)
True
Boolean
"Hello".EndsWith("W"c)
False
Boolean
stringVar.EndsWith("d"c)
True
Boolean

Equals(String) - Compares 2 Strings.

Example Method Example Return Return Type
"Hello".Equals("Hello")
True
Boolean
"Hello".Equals("Hi")
False
Boolean
stringVar.Equals("Hello World")
True
Boolean

Equals(String,String) - Compares 2 Strings.

Example Method Example Return Return Type
String.Equals("Hello","Hello")
True
Boolean
String.Equals("Hello","Hi")
False
Boolean
String.Equals(stringVar,"Hello")
False
Boolean

IsNullOrEmpty - Indicates if the String is Null or Empty.

Example Method Example Return Return Type
"Hello".IsNullOrEmpty
False
Boolean
"".IsNullOrEmpty
True
Boolean
stringVar.IsNullOrEmpty
False
Boolean

IsNullOrWhiteSpace - Indicates if the String is Null, Empty, or all WhiteSpace.

Example Method Example Return Return Type
"Hello".IsNullOrWhiteSpace
False
Boolean
" ".IsNullOrWhiteSpace
True
Boolean
stringVar.IsNullOrWhiteSpace
False
Boolean

StartsWith(String) - Check if a String starts with a specified character.

Example Method Example Return Return Type
"Hello".StartsWith("He")
True
Boolean
"Hello".StartsWith("Wo")
False
Boolean
stringVar.StartsWith("Hello")
True
Boolean

StartsWith(Char) - Check if a String starts with a specified character.

Example Method Example Return Return Type
"Hello".StartsWith("H"c)
True
Boolean
"Hello".StartsWith("W"c)
False
Boolean
stringVar.StartsWith("!"c)
False
Boolean

Conversion Methods

ToCharArray - Copies the characters in a String to a Character Array.

Example Method Example Return Return Type
"Hello".ToCharArray
{"H"c,"e"c,"l"c,"l"c,"o"c}
Array of Char
"Hi".ToCharArray
{"H"c,"i"c}
Array of Char

ToCharArray(Integer,Integer) - Copies the characters in a String to a Character Array. First integer is the starting index and the second is the length of characters to copy.

Example Method Example Return Return Type
"Hello".ToCharArray(2,3)
{"l"c,"l"c,"o"c}
Array of Char
"Hi".ToCharArray(0,1)
{"H"c}
Array of Char

ToLower - Converts a String to Lowercase

Example Method Example Return Return Type
"Hello".ToLower
"hello"
String
"WORLD".ToLower
"world"
String
stringVar.ToLower
"hello world"
String

ToString - Converts a String into a String

Example Method Example Return Return Type
"Hello".ToString
"Hello"
String
"World".ToString
"World"
String
stringVar.ToString
"Hello World"
String

ToUpper - Converts a String to Uppercase

Example Method Example Return Return Type
"Hello".ToUpper
"HELLO"
String
"World".ToUpper
"WORLD"
String
stringVar.ToUpper
"HELLO WORLD"
String

Insert(Integer,String) - Inserts a String into another String at a specified index.

Example Method Example Return Return Type
"Hello".Insert(5,"!")
"Hello!"
String
"World".Insert(0,"Hello ")
"Hello World"
String
stringVar.Insert("!",11)
"Hello World!"
String

Empty - Converts the string into an empty String

Example Method Example Return Return Type
"Hello".Empty
""
String
stringVar.Empty
""
String

Modification Methods

PadLeft(Integer) - Pads a String with WhiteSpace to the left.

Example Method Example Return Return Type
"Hello".PadLeft(8)
" Hello"
String
stringVar.PadLeft(14)
" Hello World"
String

PadLeft(Integer,Char) - Pads a String with a Character to the left.

Example Method Example Return Return Type
"Hello".PadLeft(8,"."c)
"...Hello"
String
stringVar.PadLeft(14,"."c)
"...Hello World"
String

PadRight(Integer) - Pads a String with WhiteSpace to the right.

Example Method Example Return Return Type
"Hello".PadRight(8)
"Hello "
String
stringVar.PadRight(14)
"Hello World "
String

PadRight(Integer,Char) - Pads a String with a Character to the right.

Example Method Example Return Return Type
"Hello".PadRight(8,"."c)
"Hello..."
String
stringVar.PadRight(14,"!"c)
"Hello World!!!"
String

Remove(Integer) - Removes all characters after a certain index.

Example Method Example Return Return Type
"Hello".Remove(2)
"Hel"
String
stringVar.Remove(4)
"Hello"
String

Remove(Integer,Integer) - Removes characters after a specified index for a certain length.

Example Method Example Return Return Type
"Hello".Remove(2,1)
"Helo"
String
stringVar.Remove(4,1)
"HelloWorld"
String

Replace(String,String) - Replaces a specified substring within a String with a new substring.

Example Method Example Return Return Type
"Hello".Replace("lo","p")
"Help"
String
stringVar.Replace("World","Earth")
"Hello Earth"
String

Split(Char) - Splits a String into substrings based on a character.

Example Method Example Return Return Type
"Hello".Split("e"c)
{"H","llo"}
String Array
stringVar.Split(" "c)
{"Hello","World"}
String Array

Substring(Integer) - Retrieves a substring from a String starting at a specified index.

Example Method Example Return Return Type
"Hello".Substring(2)
"lo"
String
stringVar.SubString(5)
"World"
String

Substring(Integer,Integer) - Retrieves a substring from a String starting at a specified index for a certain length.

Example Method Example Return Return Type
"Hello".Substring(2,1)
"l"
String
stringVar.SubString(5,2)
"Wo"
String

Trim - Removes leading/trailing blank spaces from a String.

Example Method Example Return Return Type
" Hello".Trim
"Hello"
String
" Hello ".Trim
"Hello"
String

Trim(Char) - Removes any instances of a certain character from a String.

Example Method Example Return Return Type
"Hello".Trim("l"c)
"Heo"
String
stringVar.Trim(" "c)
"HelloWorld"
String

TrimEnd(Char) - Removes all trailing occurrences of a character.

Example Method Example Return Return Type
"Hello!".TrimEnd("!"c)
"Hello"
String
stringVar.TrimEnd("d"c)
"Hello Worl"
String

TrimStart(Char) - Removes all starting occurrences of a character.

Example Method Example Return Return Type
"Hello!".TrimStart("H"c)
"ello!"
String
stringVar.TrimStart("H"c)
"ello World"
String

Concat(String,String,etc.) - Concatenates 2 or more strings into a single String.

Example Method Example Return Return Type
String.Concat("Hello ","World")
"Hello World"
String
String.Concat(stringVar,"!")
"Hello World!"
String

Clone - Clones a String into a new variable.

Example Method Example Return Return Type
"Hello".Clone
"Hello"
String
stringVar.Clone
"Hello World"
String