String operations

Use dynamic expressions to modify and verify data in strings. If your string contains special characters, you have to escape them. You can also use dynamic expressions with string operations.

Engines 3.0 provide on-screen descriptions of syntax and relevant examples.

To see them, start typing the relevant expression into the Value field. This opens a drop-down list where you can browse available expressions.

Available string operations

The following string operations are available in Engines 3.0:

Dynamic expressions for string operations

Expression

Description

Example

Result

{STRINGTOLOWER}

Syntax: {STRINGTOLOWER[InputText]}

Converts uppercase characters in the string to lowercase characters.

{STRINGTOLOWER[Nice Day]}

nice day

{STRINGTOUPPER}

Syntax: {STRINGTOUPPER[InputText]}

Converts lowercase characters in the string to uppercase characters.

{STRINGTOUPPER[Nice Day]}

NICE DAY

{TRIM}

Syntax: {TRIM[InputText][Optional Parameter]}

Removes whitespace characters from the start or the end of the string, or both:

  • If you don't use an optional parameter, the expression removes whitespace characters from both the start and the end of the string (default).

  • If you use the optional parameter [START], Tricentis Tosca removes whitespaces from the start of the string.

  • If you use the optional parameter [END], Tricentis Tosca removes whitespaces from the end of the string.

{TRIM[ no starting space ][START]}

no starting space

{BASE64}

Syntax: {BASE64[InputText][Parameter]}

Parameter ENCODE encodes the string to Base64 format, parameter DECODE decodes the Base64 string.

{BASE64[Hello][ENCODE]}

SGVsbG8=

{STRINGREPLACE}

Syntax: {STRINGREPLACE[InputText][Pattern][NewValue][Optional parameter1, Optional parameter2]}

Replaces all occurrences of a defined input or pattern with a new defined value.

  • If you use the optional parameter [REPLACEFIRST], Tricentis Tosca only replaces the first occurrence.

  • If you use the optional parameter [IGNORECASE], Tricentis Tosca ignores the letter case during the search.

{STRINGREPLACE[WeekEnd][e][x][IGNORECASE]}

Wxxkxnd

{NUMBEROFOCCURRENCES}

Syntax: {NUMBEROFOCCURRENCES[InputText][Pattern][Optional parameter]}

Counts all occurrences of the defined input or pattern in the string.

If you use the optional parameter [IGNORECASE], Tricentis Tosca ignores the letter case during the search.

{NUMBEROFOCCURRENCES[Mississippi][ss]}

2

{STRINGLENGTH}

Syntax: {STRINGLENGTH[InputText]}

Counts the number of characters in the string.

{STRINGLENGTH[Nice2MeetU]}

10

String operations with dynamic expressions

You can use string operations with specific text-based dynamic expressions.

This allows you, for example, to include buffers, date and time expressions, and random numbers in a string operation. For more details on specifying dynamic values, see chapter "Specify values".

To use string operations with dynamic expressions, replace the respective [InputText] of a string operation with the desired dynamic expression.

In this example, you use a buffered value in a string operation. You use the following TestSteps:

  • The TestStep TBox Clipboard (Read) buffers the content of the system clipboard to a buffer called ClipBuffer.

  • The TestStep TBox Clipboard (Write) uses the buffered content with the string operation {STRINGTOUPPER} to capitalize it.

    To do so, you write {STRINGTOUPPER[{B[ClipBuffer]}]} in the Value field.

Use a buffered value in a string operation

In this example, you use the string operation {STRINGREPLACE} to replace the number 2021 with 21, which you generate with the dynamic expression {DATE}.

To do so, you enter {STRINGREPLACE[{DATE}][2021][21]} in the Value field.

You save the new value to the clipboard with the TestStep TBox Clipboard (Write).

Use a dynamic expression in a string operation