Module Str

The Str module provides several useful operations on string values.

 

Module Str

Function

Description

Match(s: string, regexp: string): object

Tests whether s matches the regular expression regexp. If so, an object is returned where the fields of the object are integers numbered from 1 onwards, each of them having a value corresponding to the Perl5 groups (as indicated by the parenthesis sub-expressions in regexp) that has been matched. Nil is returned otherwise.

Search(s: string, regexp: string): list

Searches for all the occurrences of the regular expression regexp in s, and returns a list of objects for each of them. The fields of the objects are similar to those returned by the Match function. Note that object field 0 is the complete matched character string.

StartsWith(s: string, regexp: string): bool

Tests if a string starts with a particular pattern.

EndsWith(s: string, regexp: string): bool

Tests if a string ends with a particular pattern.

ToLowerCase(s: string): string

Turns s into lowercase.

ToUpperCase(s: string): string

Turns s into uppercase.

Replace(s: string, from: char, to: char): string

Replaces each occurrence of from with char in s.

Compare(a: string, b: string): int

Returns -1, 0, +1 if a is less than, equal, or greater than b.

EqualsIgnoreCase(a: string, b: string): bool

Tests if a and b are equal in a case-insensitive manner.

IndexOf(pat: string, s: string): int

Returns the first position where pat occurs in s, otherwise -1.

LastIndexOf(pat: string, s: string): int

Returns the last position where pat occurs in s, otherwise -1.

Split(s: string, chars: string): list

Splits the string s at positions where any of the characters of chars appear. The function returns a list of strings.


Up Previous Next