string.sub

From Garry's Mod
Revision as of 22:36, 30 July 2016 by Zerf (Talk | contribs)
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.

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