Рейтинг@Mail.ru

Module string

Замечание

Документация находится в процессе перевода и может отставать от английской версии.

Module string

Общие сведения

The string module has everything in the standard Lua string library, and some Tarantool extensions.

In this section we only discuss the additional functions that the Tarantool developers have added.

Below is a list of all additional string functions.

Name Use
string.ljust() Left-justify a string
string.rjust() Right-justify a string
string.hex() Get the hexadecimal value of a string
string.startswith() Check if a string starts with a given substring
string.endswith() Check if a string ends with a given substring
string.lstrip() Remove spaces on the left of a string
string.rstrip() Remove spaces on the right of a string
string.strip() Remove spaces on the left and right of a string
string.ljust(input-string, width[, pad-character])

Return the string left-justified in a string of length width.

Параметры:
  • input-string – (string) the string to left-justify
  • width – (integer) the width of the string after left-justifying
  • pad-character – (string) a single character, default = 1 space
Return:

left-justified string (unchanged if width <= string length)

Rtype:

string

Example:

tarantool> string = require('string')
---
...
tarantool> string.ljust(' A', 5)
---
- ' A   '
...
string.rjust(input-string, width[, pad-character])

Return the string right-justified in a string of length width.

Параметры:
  • input-string – (string) the string to right-justify
  • width – (integer) the width of the string after right-justifying
  • pad-character – (string) a single character, default = 1 space
Return:

right-justified string (unchanged if width <= string length)

Rtype:

string

Example:

tarantool> string = require('string')
---
...
tarantool> string.rjust('', 5, 'X')
---
- 'XXXXX'
...
string.hex(input-string)

Return the hexadecimal value of the input string.

Параметры:
  • input-string – (string) the string to process
Return:

hexadecimal, 2 hex-digit characters for each input character

Rtype:

string

Example:

tarantool> string = require('string')
---
...
tarantool> string.hex('ABC ')
---
- '41424320'
...
string.startswith(input-string, start-string[, start-pos[, end-pos]])

Return True if input-string starts with start-string, otherwise return False.

Параметры:
  • input-string – (string) the string where start-string should be looked for
  • start-string – (string) the string to look for
  • start-pos – (integer) position: where to start looking within input-string
  • end-pos – (integer) position: where to end looking within input-string
Return:

true / false

Rtype:

boolean

start-pos and end-pos may be negative, meaning the position should be calculated from the end of the string.

Example:

tarantool> string = require('string')
---
...
tarantool> string.startswith(' A', 'A', 2, 5)
---
- true
...
string.endswith(input-string, end-string[, start-pos[, end-pos]])

Return True if input-string ends with end-string, otherwise return False.

Параметры:
  • input-string – (string) the string where end-string should be looked for
  • end-string – (string) the string to look for
  • start-pos – (integer) position: where to start looking within input-string
  • end-pos – (integer) position: where to end looking within input-string
Return:

true / false

Rtype:

boolean

start-pos and end-pos may be negative, meaning the position should be calculated from the end of the string.

Example:

tarantool> string = require('string')
---
...
tarantool> string.endswith('Baa', 'aa')
---
- true
...
string.split(input-string[, split-string])

Split input-string into one or more output strings in a table. The places to split are the places where split-string occurs.

Параметры:
  • input-string – (string) the string to split
  • split-string – (string) the string to find within input-string. Default = space.
Return:

table of strings that were split from input-string

Rtype:

table

Example:

tarantool> fiber = require('string')
---
...
tarantool> string.split("A*BXX C", "XX")
---
- - A*B
  - ' C'
...
string.lstrip(input-string)

Return the value of the input string, but without spaces on the left.

Параметры:
  • input-string – (string) the string to process
Return:

result after stripping spaces from input string

Rtype:

string

Example:

tarantool> string = require('string')
---
...
tarantool> string.lstrip(' ABC ')
---
- 'ABC '
...
string.rstrip(input-string)

Return the value of the input string, but without spaces on the right.

Параметры:
  • input-string – (string) the string to process
Return:

result after stripping spaces from input string

Rtype:

string

Example:

tarantool> string = require('string')
---
...
tarantool> string.rstrip(' ABC ')
---
- ' ABC'
...
string.strip(input-string)

Return the value of the input string, but without spaces on the left or the right.

Параметры:
  • input-string – (string) the string to process
Return:

result after stripping spaces from input string

Rtype:

string

Example:

tarantool> string = require('string')
---
...
tarantool> string.strip(' ABC ')
---
- ABC
...