subString()

The strLib.subString()system function is used to retrieve a portion of a string. This method takes two parameters: the target string and the starting index (inclusive) of the portion of the target string to be retrieved.

Syntax

 strLib.subString(
             target STRING | CHAR | DBCHAR | MBCHAR | UNICODE In, 
             startingIndex INT In)
  returns (result STRING | CHAR | DBCHAR | MBCHAR | UNICODE))
target

Input can be any value that is assignment compatible with any of the above types.

startingIndex
An integer representing the first character (inclusive) of the substring to be retrieved.
Note:
For COBOL Generation, Negative values should not be passed into StartingIndex.
result

It returns a portion of the original string, starting from the startingIndex.

Example

  function main()
       myString String      = “Customer”;
       myChar Char(8)       = “Customer”;
       myUni Unicode(8)     = “Customer”;

       sysLib.writeStdout(“‘Customer’ from index 1: “ + strLib.subString(myString, 1)); 
       sysLib.writeStdout(“‘Customer’ from index 6: “ + strLib.subString(myChar, 6)); 
       sysLib.writeStdout(“‘Customer’ from index 7: “ + strLib.subString(myUni, 7));
   end

The output is as follows:

   ‘Customer’ from index 1 is: Customer 
   ‘Customer’ from index 6 is: mer 
   ‘Customer’ from index 7 is: er