startsWith()

The strLib.startsWith()system function is used to check if a string starts with a specified prefix. It returns “true” if the string starts with the prefix, “false” otherwise.

Syntax

  strLib.startsWith(
             target STRING | CHAR | DBCHAR | MBCHAR | UNICODE In, 
             prefix STRING | CHAR | DBCHAR | MBCHAR | UNICODE In) 
  returns (result BOOLEAN)
target

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

suffix

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

result

It returns “true” if the targetstarts with the prefix, “false” otherwise.

Example

 function main()
       myString String      = “Customer”;
       suffixString String  = “Custom”;
       myChar Char(8)       = “Customer”;
       suffixChar Char(3)   = “om”;
       myUni Unicode(8)     = “Customer”;
       suffixUni Unicode(3) = “Custom”;

       sysLib.writeStdout(“Does ‘Customer’ start with ‘Custom’? “ + strLib.starsWith(myString, prefixString)); 
       sysLib.writeStdout(“Does ‘Customer’ start with ‘om’? “ + strLib.startsWith(myChar, prefixChar)); 
       sysLib.writeStdout(“Does ‘Customer start with ‘Custom’? “ + strLib.startsWith(myUni, prefixUni));
   end

The output is as follows:

   Does ‘Customer’ start with ‘Custom’? true 
   Does ‘Customer’ start with ‘om’? false 
   Does ‘Customer’ start with ‘Custom’? true