Skip to content
QiTASC.com / General Concepts /
String Methods
/ .. /
String Methods





String Methods

The following String Methods are supported by intaQt's custom languages, and may be used in Functions, Models, Stepedefs and Reactors.

String Methods
Compare To
Concatenate
Contains
Ends With
Starts With
Equals
Index Of
Is Empty
Last Index Of
Length
Matches
Region Matches
Replace
Replace All
Replace First Substring
Substring
To Lowercase
To Uppercase
Trim

Compare To

Compares two strings lexicographically with one another.

Compare To - Case Sensitive

Case sensitive comparison of two strings.

Syntax

1
<result Number> := <firstString String>.compareTo(<secondString String>)

Returns
A positive or negative integer value, depending on whether the first string is larger or smaller than the second string.

Parameters

  • firstString - The reference string being compared against the second string

  • secondString - The string being compared against the first string

Example

1
2
stringToCompare1 := "This is a Phone"
compareResult1 := stringToCompare1.compareTo("this is a phone")

The example above returns -32.

Compare To - Ignore Case

Compares two strings while ignoring case.

Syntax

1
2
<result Number> :=
    <firstString String>.compareToIgnoreCase(<secondString String>)

Returns
A positive or negative integer value, depending on whether the first string is larger or smaller than the second string.

Parameters

  • firstString - The reference string being compared against the second string

  • secondString - The string being compared against the first string

Example

1
2
stringToCompare2 := "This is a Phone"
compareResult2 := stringToCompare2.compareToIgnoreCase("this is a phone")

The example above returns 0.

Concatenate

Concatenates the specified string to the end of another string.

Syntax

1
<result String> := <referenceString String>.concat(<toConcat String>)

Returns
The Concatenation of the reference string's characters followed by the characters specified by the concat method.

Parameters

  • referenceString - The string content that will have another string concatenated to it

  • toConcat - The string to be concatenated to the reference string

Example

1
2
stringToConcat := "text"
concatResult := stringToConcat.concat("ing")

The example above returns texting.

Contains

Checks if a string Contains the specified character sequence values. This method is case sensitive.

Syntax

1
<result Boolean> := <firstString String>.contains(<secondString String>)

Returns
true if the string Contains the specified character sequence value, false otherwise.

Parameters

  • firstString - The reference string

  • secondString - The string being checked against the reference string

Example

1
2
stringToCheck := "Hello World"
containsResult := stringToCheck.contains("hello")

The example above returns false.

Ends With

Checks if the string Ends With the specified suffix. This method is case sensitive.

Syntax

1
<result Boolean> := <firstString String>.endsWith(<suffix String>)

Returns
true if the string Ends With the specified suffix, false otherwise.

Parameters

  • firstString - The reference string

  • suffix - The suffix to check against the reference string

Example

1
2
mainString := "Hello World"
endsWithResult := mainString.endsWith("world")

The example above returns false.

Starts With

Checks that a string Starts With the specified prefix. An additional starting offset can be specified.

Syntax

1
2
3
<result Boolean> := <string String>.startsWith(<prefix String>)
<result Boolean> := <string String>.startsWith(<prefix String>,
    <offset Number>)

Returns
true if the string Starts With the specified prefix, false otherwise.

Parameters

  • string - The string being checked against the prefix

  • prefix - The prefix to match against the string

  • offset (Optional) - Indicates the offset from where the check will start

Example 1 - No Offset Specified, Returns True

1
2
exampleString := "This is an Android phone"
startsWithThis := exampleString.startsWith("This")

Example 2 - No Offset Specified, Returns False

1
2
exampleString := "This is an Android phone"
startsWithAndroid := exampleString.startsWith("Android")

Example 3 - With Offset. Returns True

1
startsWithAndroidAfterOffset := exampleString.startsWith("Android", 11)

Equals

Checks if two strings are Equal.

Equals - Case Sensitive

Case sensitive function that checks if two strings represent the same character sequence

Syntax

1
<result Boolean> := <firstString String>.equals(<secondString String>)

Returns
true when the argument is not null and the strings represent the same character sequence, false otherwise.

Parameters

  • firstString - The reference string being compared against the second string

  • secondString - The string being compared against the reference string

Example

1
2
equalsToCheck := "hello"
equalsResult := equalsToCheck.equals("Hello")

The example above returns false, because the cases do not match.

Equals - Ignore Case

Function that checks if two strings represent the same character sequence, and ignores case.

Syntax

1
<result Boolean> := <firstString String>.equalsIgnoreCase(<secondString String>)

Returns
true when the argument is not null and the strings represent the same character sequence, false otherwise.

Parameters

  • firstString - The reference string being compared against the second string

  • secondString - The string being compared against the reference string

Example

1
2
equalsToCheck := "hello"
equalsIgnoreCaseResult := equalsToCheck.equalsIgnoreCase("Hello")

The example above returns true because the character sequences match and the function ignores case.

Index Of

Returns the Index Of the first occurrence of the specified substring. An additional index position may be specified, which is used to search from that specified index.

Syntax

1
2
<result Number> := <firstString String>.indexOf(<substring String>,
    <fromIndex Number>)

Returns
The Index Of the first occurrence of the specified substring, or -1 if the string argument does not occur as part of the string.

Parameters

  • firstString - The reference string whose content will be checked

  • substring - The substring whose index position will be returned

  • fromIndex (Optional) - The index from which to start the search

Example 1 - Without Specified Index

1
2
stringToCheck := "Hello"
indexOfLL1 := stringToCheck.indexOf("ll")

The example above returns 2.

Example 2 - With Specified Index

1
indexofLL2 := stringToCheck.indexOf("ll", 4)

The example above returns -1.

Last Index Of

Returns the substring's index from its rightmost position. An additional index position may be specified, which is used to search backwards, starting from that specified index.

Syntax

1
2
<result Number> := <string String>.lastIndexOf(<substring String>,
    <fromIndex Number>)

Returns
The index of the character's last occurrence in a sequence, or -1 if the character does not exist.

Parameters

  • string - The string being checked

  • substring - The substring whose rightmost index position will be returned

  • fromIndex (Optional) - The index from which to start the search

Example 1 - Without Specified Index

1
2
stringToCheck := "This is an Android phone"
lastIndexOfAndroid1 := stringToCheck.lastIndexOf("Android")

The example above returns 11.

Example 2 - With Specified Index

1
2
stringToCheck := "This is an Android phone"
LastIndexOfAndroid2 := stringToCheck.lastIndexOf("Android", 8)

The example above returns -1.

Is Empty

Checks if a string Is Empty.

Syntax

1
<result Boolean> := <string String>.isEmpty()

Returns
true if the string's length is 0, false otherwise.

Parameter

  • string - The string whose content will be checked

Example 1 - Returns True

1
2
isItEmpty := ""
isEmptyResult := isItEmpty.isEmpty()

Example 2 - Returns False

1
2
isItNotEmpty := "42"
IsItNotEmptyResult := isItNotEmpty.isEmpty()

Length

Returns the string's Length.

Syntax

1
<result Number> := <string String>.length()

Returns
The character sequence length.

Parameter

  • string - The string whose length is being checked

Example

1
2
helloWorldString := "Hello World"
stringLength := helloWorldString.length()

The example above returns 11.

Matches

Checks if the string Matches the given regular expression.

Syntax

1
<result Boolean> := <string String>.matches(<regex String>)

Returns
true if the string matches the regular expression, false otherwise.

Parameters

  • string - The string being matched against the regex

  • regex - The regex to be matched

Example

1
2
helloWorldString := "hello.world"
matchesResult := helloWorldString.matches("hello.*")

The example above returns true.

Region Matches

Checks if two region strings match.

Syntax

1
2
<result Boolean> := <string1 String>.regionMatches(<ignoreCase Boolean>,
    <offset1 Number>, <string2 String>, <offset2 Number>, <length Number>)

Returns
true if two region strings match, false otherwise.

Parameters

  • string1 - The reference string whose subregion will be compared against a second string's subregion

  • offset1 - The starting offset of a string's subregion

  • string2 - The second string object to compare with the first

  • offset2 - The starting offset of the second string's subregion

  • length - The number of characters to compare

  • ignoreCase (Optional) -

  • true, ignores case when comparing characters
  • false if unspecified

Example 1 - Ignores Case

1
2
3
androidPhoneString1 := "This is an Android phone"
stringToCompare := "This is another Android Phone"
checkMatch1 := androidPhoneString1.regionMatches(true, 19, stringToCompare, 24, 5)

The example above returns true.

Example 2 - Case Sensitive

1
2
3
androidPhoneString2 := "This is another Android Phone"
stringToCompare := "This is another Android Phone"
checkMatch2 := androidPhoneString2.regionMatches(19, stringToCompare, 24, 5)

The example above returns false.

Replace

Returns a new string resulting from replacing all occurrences of toReplace string in this string with replaceWith string.

Syntax

1
2
<result String> := <firstString String>.replace(<toReplace String>,
    <replaceWith String>)

Returns
A new string resulting from replacing all occurrences of the toReplace with replaceWith string.

Parameters

  • firstString - The reference string

  • toReplace - The string content that will be replaced

  • replaceWith - The string that will replace the reference string

Example

1
2
mainString := "This is an Android phone"
resultingString := mainString.replace("an Android", "a Snom")

The example above returns "This is a Snom phone".

Replace All

Replaces each substring of reference string that matches the regular expression with the given replacement.

Syntax

1
2
<result String> := <firstString String>.replaceAll(<regex String>,
    <replaceWith String>)

Returns
A new string resulting from replacing all substrings that match the regex string with the replaceWith string.

Parameters

  • firstString - The reference string

  • regex - The regex to be matched

  • replaceWith - The string to be substituted for each match

Example

1
2
mainString := "abc145x2y"
resultingString := mainString.replaceAll("\\d", "Z")

The example above returns "abcZZZxZy".

Note:

  • Multiline mode must be turned on in order to match line-based content(for example, ^ to mark the beginning of the line, or $ to mark the end of the line).

  • Multiline mode is deactivated by default, but can be activated by using (?m) at the beginning of a regex.

Replace First

Replaces the first substring that matches the regular expression with the given replacement.

Syntax

1
2
<result String> := <firstString String>.replaceFirst(<regex String>,
    <replaceWith String>)

Returns
A new string resulting from replacing the first substring that matches the regex string with the replaceWith string.

Parameters

  • firstString - The reference string

  • regex - The regex to be matched

  • replaceWith - The string to be substituted for each match

Example

1
2
mainString := "abc145x2y"
resultingString := mainString.replaceFirst("\\d", "Z")

The example above returns "abcZ45x2y".

Substring

Returns a new string from a specified Substring. This is done by specifying a starting index position from where the Substring will be created. An additional ending index position can be specified.

Syntax

1
<result String> := <string String>.substring(<beginIndex Number>, <endIndex Number>)

Returns
The new Substring.

Parameters

  • string - The reference string

  • beginIndex - The index position from where the substring will be created

  • endIndex (Optional) - The index position from where the substring will end

Example 1 - Without End Offset

1
2
string1    := "telephone"
substring1 := string1.substring(4)

The example above returns phone.

Example 2 - With End Offset

1
2
string2    := "facsimiles"
substring2 := string2.substring(5, 9)

The example above returns mile.

To Lowercase

Converts a string's characters to lowercase according to the default locale rules.

Syntax

1
<result String> := <string String>.toLowerCase()

Returns
The string converted to lowercase.

Parameter

  • string - The string to convert to lowercase

Example

1
2
exampleString := "This is a Phone"
lowerCaseString := exampleString.toLowerCase()

The example above returns "this is a phone".

To Uppercase

Converts a string's characters to uppercase according to the default locale rules.

Syntax

1
<result String> := <string String>.toUpperCase()

Returns
The string converted to uppercase.

Parameter

  • string - The string to convert to uppercase

Example

1
2
exampleString := "this is a phone"
upperCaseString := exampleString.toUpperCase()

The example above returns "THIS IS A PHONE".

Trim

Returns a copy of the string without any leading or trailing white spaces.

Syntax

1
<result String> := <string String>.trim()

Returns
The trimmed string.

Parameters

  • string - The string to trim

Example

1
2
exampleString := "     This is a Phone "
trimmedString := exampleString.trim()

The example above returns "This is a Phone".