The String Class

The String class provides methods for working with text.

Syntax

String

Methods

Table 1. Object Methods
Name Description
charAt(index Numeric)
  RETURNING result String
Returns a String containing the character at the specified index in the current String.
contains(s String)
  RETURNING result Boolean
Returns a Boolean value (TRUE/FALSE) specifying whether s is contained within the current String.
endsWith(s String)
  RETURNING result Boolean
Returns a Boolean value (TRUE/FALSE) specifying whether the current String ends with s.
equals(s String) 
  RETURNING result Boolean
Returns a Boolean value (TRUE/FALSE) specifying whether s matches the current String. If one of the Strings is null the method returns FALSE.
equalsIgnoreCase(s String)
  RETURNING result Boolean
Returns a Boolean value (TRUE/FALSE) specifying whether s matches the current String, ignoring character case. If one of the Strings is null the method returns FALSE.
format (number Numeric, format Enum)
  RETURNING result String
Sets the format of the page number string for a PAGENOBOX. The value for format can be: ARABIC, LOWERROMAN, UPPERROMAN
indexOf(s String)
  RETURNING result Numeric
 
Returns a Numeric value representing the index of s within the current String.
indexOf(s String , index Numeric)
  RETURNING result Numeric
Returns a Numeric value representing the index of s within the current String, starting from byte position index. Returns zero if the substring was not found. Returns -1 if the current String is null.
isEmpty()
  RETURNING result Boolean
Returns a Boolean value. Returns true if the current string has a length of zero (length()=0), otherwise false.
isNull()
  RETURNING result Boolean
Returns a Boolean value. Returns true if the current string has a length of zero (length()=0) and the string is tagged as null, otherwise false. This is the case for null valued input variables read from the input stream.

For backward compatibility, null values do not have special behavior when used with the various operators. Specifically an input variable of type string that is null behaves like the empty string.

lastIndexOf(s String) 
  RETURNING result Numeric
Returns a Numeric value representing the index within the current String of the last occurrence of s, searching backward.
lastIndexOf(s String , index Numeric) 
  RETURNING result Numeric
Returns a Numeric value representing the index within the current String of the last occurrence of s, searching backward. starting at the specified position index.
length()
  RETURNING result Numeric
Returns a Numeric value representing the length of the current String.
matches(s String)
  RETURNING result Boolean
Returns a Boolean value specifying whether the current String matches the regular expressions.
replace(old String, new String)
  RETURNING result String
Replaces old in the current String with new.
replaceAll(old String, new String)
  RETURNING result String
Replaces every occurrence of old in the current String with new.
replaceFirst(old String, new String)
  RETURNING result String
Replaces every occurrence of old in the current String with new.
startsWith(s String)
  RETURNING result Boolean
Returns a Boolean value specifying whether the current String begins with s.
startsWith(s String , index Numeric)
  RETURNING result Boolean
Returns a Boolean value specifying whether the substring in the current String beginning at the position index contains s. The first byte of a string is at position 0.
subString(sindex Numeric, eindex Numeric)
  RETURNING result String
Returns the substring starting at byte position sindex and ending at the character at eindex-1. The first byte of a string is at position 0.
subString(index Numeric)
  RETURNING result String
Returns the substring starting at the position index in the current String. The first byte of a string is at position 0.
toLowerCase()
  RETURNING result String
Converts the current String to lowercase.
toString()
  RETURNING result String 
Converts the current Numeric value to a String.
toUpperCase()
  RETURNING result String
Converts the current String to uppercase.
translate()
  RETURNING result String
Uses the current String as the key for a lookup in Genero localization files; returns any entry found, otherwise returns the current String itself.
trim()
  RETURNING result String
Removes white space characters from the beginning and end of the current String.
trimCompress()
  RETURNING result String
Removes white space characters at the beginning and end of the current String, as well as any contained white space.
trimLeft()
  RETURNING result String
Removes white space characters from the beginning of the current String.
trimRight()
  RETURNING result String
Removes white space characters from the end of the current String.
urlEncode()
  RETURNING result String
Returns a URL encoding of the current String.

Usage and Examples

With RTL classes, it is not possible to create and subclass objects. The new keyword is not supported.

All literal String values in an expression must be delimited by double quotes.

All the methods require an object instance. When you invoke the method, it is prefixed with the object instance name and the "." character. You can get an object instance by referencing a variable or by calling a method on another object. The object can be a literal value, for example:

"Test".length()

Numeric data items in WordBoxes and WordWrapBoxes

If you enter an expression for the text property of a WordBox or WordWrapBox, the value must be a String. You can use the toString() function in your expressions to convert numbers to Strings. When you drag a Numeric data item onto the Report Design Window, it is automatically placed in a WordBox element, and an expression for the text property is created to convert it to a String.

For example:

order_line.unitprice.toString()

The indexes of a String (example subString)

When specifying the character position (index) of a string, the first character value is at position 0.

For example, when using the subString() function, the substring begins at the specified startindex and ends at the character at endindex -1. The length of the string is endindex minus startIndex:

order_line.billState.subString(1,5) 

If the value of the String billState is "smiles" (indexes 012345), the substring returned is "mile", and the length of the string is 5 minus 1 = 4.

Concatenating Strings

Use the + operator to concatenate strings. For example:

("Total:"+" "+order_line.totalorderprice).toString()

This expression returns the current value of totalorderprice as part of a String value:

Total: 12.95