🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators subString
Created by Lars.olofsson on 2019-11-18 · Last edited by Sandra.akech on 2026-02-07.

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

Returns a string containing all characters from self, starting from index *lower* up to index *upper* included. Both *lower* and *upper* parameters should be contained between *1* and *self.size()* included. *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