string.ToTable
From Garry's Mod
Contents |
Description
Splits the string into characters and creates a sequential table of characters.
WARNING |
As a result of the UTF-8 encoding, non-ASCII characters will be split into more than one character in the output table. Each character value in the output table will always be 1 byte. |
Arguments
string str
The string you'll turn into a table.
Returns
A sequential table where each value is a character from the given string
Examples
Example
Demonstrates the use of this function.
local mystring = "text" PrintTable(string.ToTable(mystring))
Output:
1 = t 2 = e 3 = x 4 = t
Examples
Example
Demonstrates how this function behaves with non-ASCII characters - in this case, Greek letters.
for k,v in ipairs(string.ToTable("abcd αβγδ")) do print(k, bit.tohex(string.byte(v)), v) end
Output:
1 00000061 a 2 00000062 b 3 00000063 c 4 00000064 d 5 00000020 6 000000ce ? 7 000000b1 ? 8 000000ce ? 9 000000b2 ? 10 000000ce ? 11 000000b3 ? 12 000000ce ? 13 000000b4 ?