charAt()

The strLib.charAt()system function returns the character at the specified index in the string.

Syntax

      strLib.charAt(
                 source STRING | CHAR | DBCHAR | MBCHAR | UNICODE In,
                 index INT In)
      returns (result STRING | CHAR | DBCHAR | MBCHAR | UNICODE)
source
Input can be any value that is assignment compatible with any of the above types.
index
An INT variable representing the index of the character to return.
result
The value at the specified index of the source, that is assignment compatible with any of the above types. The following values for result have a special meaning:
-1

The index is out of bound.

Example

Consider the following code:


function main()
  myString String        = “ABCDE”;
  myChar Char(5)         = “ABCDE”;
  myMbChar MbChar(5)     = “ABCDE”; 
  myDbChar DbChar(5)     = “ABCDE”; 
  myUnicode Unicode(5)   = “ABCDE”;
 
  sysLib.writeStdout(strLib.charAt(myString, 3) + “ is the third character of String”); 
  sysLib.writeStdout(strLib.charAt(myChar, 3) + “ is the third character of Char”); 
  sysLib.writeStdout(strLib.charAt(myMbChar, 3) + “ is the third character of MbChar”); 
  sysLib.writeStdout(strLib.charAt(myDbChar, 3) + “ is the third character of DbChar”); 
  sysLib.writeStdout(strLib.charAt(myUnicode, 3) + “ is the third character of Unicode”);
end

The output is as follows:


C is the third character of String 
C is the third character of Char
C is the third character of MbChar
C is the third character of DbChar 
C is the third character of Unicode