Next: 6.3 Mathematical Functions Up: 6 Predefined Functions and Previous: 6.1 Predefined Functions

6.2 String Manipulation

This library provides generic functions for string manipulation, such as finding and extracting substrings. When indexing a string, the first character has position 1. See Section 7.2 for some examples on string manipulation in Lua.

strfind (str, substr, [init, [end]])

Receives two string arguments, and returns a number. This number indicates the first position where the second argument appears in the first argument. If the second argument is not a substring of the first one, then strfind returns nil. A third optional numerical argument specifies where to start the search. Another optional numerical argument specifies where to stop it.

strlen (s)

Receives a string and returns its length.

strsub (s, i, [j])

Returns another string, which is a substring of s, starting at i and runing until j. If j is absent, it is assumed to be equal to the length of s. Particularly, the call strsub(s,1,j) returns a prefix of s with length j, while the call strsub(s,i) returns a suffix of s, starting at i.

strlower (s)

Receives a string and returns a copy of that string with all upper case letters changed to lower case. All other characters are left unchanged.

strupper (s)

Receives a string and returns a copy of that string with all lower case letters changed to upper case. All other characters are left unchanged.

ascii (s, [i])

Returns the ascii code of the character s[i]. If i is absent, it is assumed to be 1.

int2str ({i})

Receives 0 or more numbers. Returns a string with length equal to the number of arguments, wherein each character has ascii value equal to its correspondent argument.

Next: 6.3 Mathematical Functions Up: 6 Predefined Functions and Previous: 6.1 Predefined Functions