Garry's Mod Wiki

string.ToTable

  table string.ToTable( string str )

Description

Splits the string into characters and creates a sequential table of characters.

As a result of the 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

1 string str
The string you'll turn into a table.

Returns

1 table
A sequential table where each value is a character from the given string

Example

Demonstrates the use of this function.

local mystring = "text" PrintTable( string.ToTable( mystring ) )
Output:
1 = t 2 = e 3 = x 4 = t

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 ?