Function
indexOf(_:_:)
Finds the index of the first occurrence of a substring within a string.
func indexOf(_ string: any EcoreValue, _ substring: any EcoreValue) throws -> EInt
Parameters
string-
The string to search in
substring-
The substring to search for
Return Value
The 1-based index of the first occurrence, or 0 if not found
Discussion
The indexOf operation searches for the first occurrence of the specified substring and returns its 1-based index. If the substring is not found, it returns 0 (following OCL conventions).
Examples
let text = "Hello World" as EString
let index = try indexOf(text, "World") // Result: 7
let notFound = try indexOf(text, "xyz") // Result: 0