Searching & Testing
Last updated
Methods that inspect a string's contents. Positions are 1-indexed; "not found" is 0.
.contains(substr) → booleanWhether the string contains substr.
.containsAny(...subs) → booleanWhether the string contains any one of the given substrings.
.startsWith(prefix) → booleanWhether the string begins with prefix.
.endsWith(suffix) → booleanWhether the string ends with suffix.
log "report.csv".endsWith(".csv") // true
log "abc".containsAny("x", "b") // true.index(substr) → numberPosition of the first occurrence of substr (1-indexed), or 0 if absent.
.lastIndex(substr) → numberPosition of the last occurrence (1-indexed), or 0 if absent.
.count(substr) → numberNumber of times substr appears.
Last updated
log "hello world".index("o") // 5
log "hello world".lastIndex("o") // 8
log "a-b-c".count("-") // 2