string

Mostrar obsoleto

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.

Resumo

Funções

  • 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.

Funções

byte

Parâmetros

Valor Padrão: 1
Valor Padrão: i

Devolução

char

Parâmetros

...: number

Devolução

find

Parâmetros

pattern: string
init: number
Valor Padrão: 1
plain: boolean
Valor Padrão: false

Devolução

format

Parâmetros

formatstring: string
...: string

Devolução

gmatch

Parâmetros

pattern: string

Devolução

gsub

Parâmetros

pattern: string
replacement: Variant
replacements: number

Devolução

Parâmetros

Devolução

lower

Parâmetros

Devolução

match

Parâmetros

pattern: string
init: number
Valor Padrão: 1

Devolução

pack

Parâmetros

format: string
...: Variant

Devolução

packsize

Parâmetros

format: string

Devolução

Parâmetros

Devolução

reverse

Parâmetros

Devolução

split

Parâmetros

separator: string
Valor Padrão: ,

Devolução

Parâmetros

Valor Padrão: 1
Valor Padrão: -1

Devolução

unpack

Parâmetros

format: string
data: string
readStart: string
Valor Padrão: 1

Devolução

upper

Parâmetros

Devolução