string.char

From Garry's Mod
Jump to: navigation, search
 string.char( )

Contents

Description

Takes the given numerical bytes and converts them to a string.

Arguments

vararg bytes

The bytes to create the string from.

Returns

string

String built from given bytes

Examples

Example

Prints a string consisting of the bytes 72, 101, 108, 108, 111

print( string.char( 72, 101, 108, 108, 111 ) )

Output:

Hello

Examples

Example

Helper function to create a random string.

function string.Random( length )

	local length = tonumber( length )

    if length < 1 then return end

    local result = "" -- The empty string we start with

    for i = 1, length do

        result = result .. string.char( math.random(32, 126) )

    end

    return result

end

print( string.Random( 10 ) )

Output:

oEjkv2?h:T
Personal tools
Navigation