string.sub

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

Contents

Description

Returns a sub-string, starting from the character at position StartPos of the string (inclusive), and optionally ending at the character at position EndPos of the string (also inclusive). If EndPos is not given, the rest of the string is returned.

Arguments

string string

The string you'll take a sub-string out of.

Arguments

number StartPos

The position of the first character that will be included in the sub-string.

Arguments

number EndPos=nil

The position of the last character to be included in the sub-string. It can be negative to count from the end.

Returns

string

The substring.

Examples

Example

Demonstrates the use of this function.

local mystring = "Some random text"
print(string.sub(mystring, 1, 4))

Output:

Some
Personal tools
Navigation