You are here

Working with strings in TestComplete

Basics
A String is a sequence of symbols or digits. Strings are among the most frequently used data types. Like any other data type, strings in TestComplete are represented as OLE-compatible variants. In scripting, a sequence of literal characters, enclosed in double quotes ("), is recognized as a string. Single quotation marks (') are allowed within a string. To insert a double quotation mark into a string, it should be duplicated. The following is an example of string:

Scripting

str1 = "The buswas heading to London, when the driver noticed a cat on the road."
str2 = "'Ahoy! Is there anyone?' - the captain cried."
str3 = """Nobody."" - was the answer."

To work with strings, TestComplete has a special scripting object - aqString. The object is available for all supported scripting languages, so you can use it to work with string values regardless of the chosen language.

Method, Property

Description

aqString.AddListItem

Adds a new item to a string list.

aqString.ChangeListItem

Changes the value of the string list item with the given index.

aqString.Compare

Compares two specified strings.

aqString.Concat

Concatenates two specified strings.

aqString.DeleteListItem

Removes an item with the given index from a string list.

aqString.Find

Searches for a substring within the given string. Use this method instead of the obsolete aqString.Contains.

aqString.Format

Generates a formatted string.

aqString.GetChar

Retrieves a single character from the input string.

aqString.GetLength

Returns the number of characters in a string.

aqString.GetListItem

Returns an individual item from the list passed through the input string.

aqString.GetListLength

Returns the number of items in the string list.

aqString.Insert

Inserts one string to another at the specified position.

aqString.ListSeparator

Specifies a character used to separate individual values in a list.

aqString.Quote

Encloses the specified string in quotes.

aqString.QuoteSymbol

Specifies a symbol used as a quotation mark.

aqString.Remove

Removes a number of characters from the input string.

aqString.Replace

Replaces all the occurrences of one substring with another substring.

aqString.SubString

Retrieves a substring from the input string.

aqString.ToLower

Converts the specified string to lower case.

aqString.ToUpper

Converts the specified string to upper case.

aqString.Trim

Removes spaces and control characters from the specified string.

aqString.Unquote

Converts a quoted string to an unquoted string.

Another scripting object that can be used to work with strings is aqConvert. This object has several methods that convert values of different types to a string and vice versa.

Method

Description

aqConvert.CurrencyToFormatStr

Converts a currency value to a string using the specified format settings.

aqConvert.CurrencyToStr

Converts a currency value to a string.

aqConvert.DateTimeToFormatStr

Converts the given date value to a string using the specified format.

aqConvert.DateTimeToStr

Converts the given date value to a string.

aqConvert.FloatToStr

Converts a floating-point value to a string.

aqConvert.IntToStr

Converts the given number into a string.

aqConvert.StrToCurrency

Converts the specified string to a currency value.

aqConvert.StrToDate

Converts the specified string to a date value.

aqConvert.StrToDateTime

Converts the specified string to a date/time value.

aqConvert.StrToFloat

Converts the specified string to a floating-point value.

aqConvert.StrToInt

Converts the specified string to an integer value.

aqConvert.StrToTime

Converts the specified string to a time value.

aqConvert.VarToStr

Converts the specified variant value to a string.