indexOf

indexOf, function

def const pure indexOf(source: text, pattern: text): number

Returns the zero-based index of the first occurrence of pattern in source, or -1 if not found.

Examples

source = "Hello World!"

table T = with
  [| as Pattern |]
  [| "o" |]
  [| "!" |]
  [| "Z" |]

T.Index = indexOf(source, T.Pattern)

show table "Index" with
  T.Pattern
  T.Index

This produces the following table:

Pattern Index
o 4
! 11
Z -1

Remarks

indexOf is often used with substr.

See also

User Contributed Notes
0 notes + add a note