🚀 Welcome to MDriven Learn –  Don’t miss the latest Release Notes.
OCLOperators subString

substring ( lower : Integer, upper : Integer ) : String

Returns a string containing all characters from self, starting from index *lower* up to and including index *upper*. Both *lower* and *upper* parameters should be between *1* and *self.size()*, inclusive. *lower* cannot be greater than *upper*.

Expression Result
'substring operation'.substring(11, 19) 'operation'
'substring operation'.substring(1, 1) 's'
'substring operation'.substring(0, 1) invalid
The subString operator extracts a portion of a string based on start and end positions. It returns a substring containing all characters from the start position up to and including the end position.

Syntax:

string.subString(lower : Integer, upper : Integer) : String

Parameters

  • lower (Integer): The starting position (1-based, inclusive)
  • upper (Integer): The ending position (1-based, inclusive)

Return Type

  • String - The extracted substring


Examples:

Invalid Index:

'substring operation'.subString(0, 1)

Result:

Invalid/Error

Index 0 is invalid (must start at 1).


Example: Extract First Word

'Hello World'.subString(1, 5)

Result:

Hello