string

Show Deprecated

The string library provides generic functions to manipulate strings, such as to extract substrings or match patterns. You can access the string library by the global string library.

See String pattern reference for details on using string.match(), string.gmatch(), and string.gsub() to find (and replace) substrings.

Summary

Functions

  • Returns the internal numerical codes of the characters s[i], s[i+1], ..., s[j]. The default value for i is 1; the default value for j is i. These indices are corrected following the same rules of function string.sub.

  • Receives zero or more integers and returns a string with length equal to the number of arguments, in which each character has the internal numerical code equal to its corresponding argument.

  • find(s : string,pattern : string,init : number,plain : boolean):number,number

    Looks for the first match of pattern in the string s and returns the indices of s where the occurrence starts and ends.

  • format(formatstring : string,... : string):string

    Returns a formatted version of its variable number of arguments following the description given in its first argument, which must be a string.

  • gmatch(s : string,pattern : string):function

    Returns an iterator function that returns the next captures from pattern over the string s each time it's called.

  • gsub(s : string,pattern : string,replacement : Variant,replacements : number):string,number

    Returns a copy of s in which all or the first n occurrences of the pattern are replaced with the given replacement. The second value returned is the total number of substitutions made.

  • Returns the length of a string.

  • Returns a copy of a string with all uppercase letters changed to lowercase.

  • match(s : string,pattern : string,init : number):string

    Looks for the first match of pattern in the string s. If a match is found, it is returned; otherwise, it returns nil. A third, optional numerical argument, init, specifies where to start the search.

  • pack(format : string,... : Variant):string

    Returns a binary string containing the provided arguments.

  • Returns the size in bytes of any string packed with a given description.

  • Returns a string that is the concatenation of n copies of the string s.

  • Returns a string that is the string s reversed.

  • split(s : string,separator : string):table

    Splits a string into parts based on the defined separator character(s), returning a table of ordered results.

  • Returns the substring of s that starts at i and continues until and including j. i and j can be negative. i defaults to 1 and j defaults to -1.

  • unpack(format : string,data : string,readStart : string):Tuple

    Extracts the values packed in the provided binary string.

  • Returns a copy of a string with all lowercase letters changed to uppercase.

Functions

byte

Parameters

Default Value: 1
Default Value: i

Returns

char

Parameters

...: number

Returns

find

Parameters

pattern: string
init: number
Default Value: 1
plain: boolean
Default Value: false

format

Parameters

formatstring: string
...: string

Returns

gmatch

Parameters

pattern: string

Returns

gsub

Parameters

pattern: string
replacement: Variant
replacements: number

Parameters

Returns

lower

Parameters

Returns

match

Parameters

pattern: string
init: number
Default Value: 1

Returns

pack

Parameters

format: string
...: Variant

Returns

packsize

Parameters

format: string

Returns

Parameters

Returns

reverse

Parameters

Returns

split

Parameters

separator: string
Default Value: ,

Returns

Parameters

Default Value: 1
Default Value: -1

Returns

unpack

Parameters

format: string
data: string
readStart: string
Default Value: 1

Returns

upper

Parameters

Returns