Previous Document Next Document

What query methods are supported for strings?

All common query methods (see the section “What common query methods are supported?”) are supported for strings.

The following query methods are also supported for strings:

Method
Description
Example
Result
string.Length()
Returns the length of the string
'test'.length
4
string.Empty()
Returns True if the string is empty
'test'.empty
False
string.ToUpper()
Converts the string to uppercase
'test'.ToUpper
'TEST'
string.ToLower()
Converts the string to lowercase
'TEST'.ToLower
'test'
string.ToTitle()
Converts the string to title case
'TEST'.ToTitle
'Test'
string.CharCode()
Gets the Unicode character code of the first string character
'Test'.CharCode
84
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)
'World'
 
 
'Hello World'.SubStr(6,3)
'Wor'
 
The first index can be negative, to specify the index from the end of the string.
'This is a test'.SubStr(-4)
'test'
 
If the last parameter is negative, it indicates the last character from the end of the string.
'Some words'.SubStr(5, -1)
'word'
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)
'abfg'
 
 
'abcdefg'.Delete(-2)
'abcdeg'
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()
'test'
 
 
'aaaaatestbbbccc'.trim('abc')
'test'
string.LTrim([string])
Similar to the Trim function, but removes the characters only from the beginning of the string
' test '.trim()
'test '
string.RTrim([string])
Similar to the Trim function, but removes the characters only from the end of the string
' test '.trim()
' test'
string.Repeat(int)
Repeats the string the specified number of times
'test'.repeat(3)
'testtesttest'
string.StartsWith(string)
Returns True if the string starts with the specified string
'Apple'.StartsWith('A')
True
string.EndsWith(string)
Returns True if the string ends with the specified string
'Cooking'.EndsWith('ing')
True
string.Contains(string)
Returns True if the string contains the specified string
'Peaceful world'.Contains('Peace')
True
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')
'green pencil, blue pencil'
string.Split(string)
Splits the string delimited with the specified characters into an array of strings
'Design<->Implementation<->Testing'.Split('<->')
array('Design', 'Implementation', 'Testing')
string.CharAt(int)
Gets the character at the given index in the string. The index is zero-based.
'Test'.CharAt(1)
'e'
string.CharCodeAt(int)
Gets the Unicode character code of the character at the given index. The index is zero-based.
'ABCD'.CharCodeAt(3)
68
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')
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')
5
string.ToCharArray()
Converts the string into an array of characters
'abc'.ToCharArray
array('a', 'b', 'c')

Previous Document Next Document Back to Top

Copyright 2007 Corel Corporation. All rights reserved.