Previous Document Next Document

Including queries in macros : Understanding the available query criteria : Querying strings


Querying strings

Strings support all common query criteria (see Understanding the available query criteria).

Strings also support the following query criteria:

Query criteria
Description
Example and result
string.CharAt(int)
Gets the character at the given index in the string. The index is zero-based.
'Test'.CharAt(1)
Yields 'e'
string.CharCode()
Gets the Unicode character code of the first string character
'Test'.CharCode
Yields 84
string.CharCodeAt(int)
Gets the Unicode character code of the character at the given index. The index is zero-based.
'ABCD'.CharCodeAt(3)
Yields 68
string.Contains(string)
Returns True if the string contains the specified string
'Dogs'.Contains('Dog')
Yields True
string.Delete(int, [int])
Removes the specified characters from the string. The meaning of the parameters is the same as those of SubStr function.
'abcdefg'.Delete(2, 3)
Yields 'abfg'
 
 
'abcdefg'.Delete(-2)
Yields 'abcdeg'
string.Empty()
Returns True if the string is empty
'test'.empty
Yields False
string.EndsWith(string)
Returns True if the string ends with the specified string
'Doing'.EndsWith('ing')
Yields True
string.IndexOf(string)
Finds a substring and returns the character index of its first occurrence. If it is not found, -1 is returned.
'this is a test'
.IndexOf('is')
Yields 2
string.LastIndexOf(string)
Finds a substring and returns the character index of its last occurrence. If it is not found, -1 is returned.
'this is a test'
.LastIndexOf('is')
Yields 5
string.Length()
Returns the length of the string
'test'.length
Yields 4
string.LTrim([string])
Similar to the Trim function, but removes the characters only from the beginning of the string
' test '.trim()
Yields 'test '
string.Repeat(int)
Repeats the string the specified number of times
'test'.repeat(3)
Yields 'testtesttest'
string.Replace(string, string)
Replaces all instances of the search substring (the first parameter) with the replacement string (the second parameter)
'green pen, blue pen'
.Replace('pen', 'pencil')
Yields 'green pencil, blue pencil'
string.RTrim([string])
Similar to the Trim function, but removes the characters only from the end of the string
' test '.trim()
Yields ' test'
string.Split(string)
Splits the string delimited with the specified characters into an array of strings
'Design<->Implementation
<->Testing'.Split('<->')
Yields array('Design', 'Implementation', 'Testing')
string.StartsWith(string)
Returns True if the string starts with the specified string
'Apple'.StartsWith('A')
Yields True
string.SubStr(int, [int])
Gets a substring of a string. The first parameter is a zero-based index of the first character to include in the substring. The second optional parameter is the length of the substring to retrieve. If it is omitted, the whole remainder of the string is returned.
'Hello World'.SubStr(6)
Yields 'World'
 
 
'Hello World'.SubStr(6,3)
Yields 'Wor'
 
The first index can be negative, to specify the index from the end of the string.
'This is a test'.SubStr(-4)
Yields 'test'
 
If the last parameter is negative, it indicates the last character from the end of the string.
'Some words'.SubStr(5, -1)
Yields 'word'
string.ToCharArray()
Converts the string into an array of characters
'abc'.ToCharArray
Yields array('a', 'b', 'c')
string.ToLower()
Converts the string to lowercase
'TEST'.ToLower
Yields 'test'
string.ToTitle()
Converts the string to title case
'TEST'.ToTitle
Yields 'Test'
string.ToUpper()
Converts the string to uppercase
'test'.ToUpper
Yields 'TEST'
string.Trim([string])
Removes the specified characters from the beginning and end of the string. If the optional string parameter is omitted, then space (code 32) and tab (code 9) characters are removed.
' test '.trim()
Yields 'test'
 
 
'aaaatestbbcc'.trim('abc')
Yields 'test'

Previous Document Next Document Back to Top

Copyright 2013 Corel Corporation. All rights reserved.