C# Class GarrysModLuaShared.@string

The string type is a sequence of characters. The string library is a standard Lua library which provides functions for the manipulation of strings. In Garry's Mod there are several extra useful functions added to this library.
显示文件 Open project: OmegaExtern/gmod-csharp-binary-module

Public Methods

Method Description
@byte ( LuaState luaState, string inputString, uint startPos = 1U, uint endPos = 1U ) : byte[]

Returns the given string's characters in their numeric ASCII representation.

@char ( LuaState luaState ) : string

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

Comma ( LuaState luaState, double inputNumber ) : string

Inserts commas for every third digit.

EndsWith ( LuaState luaState, string inputString, string endString ) : bool

Returns whether or not the second passed string matches the end of the first.

FormattedTime ( LuaState luaState, double @float, string format ) : string

Returns the time as a formatted string or as a table if no format is given.

GetExtensionFromFilename ( LuaState luaState, string fileName ) : string

Returns extension of the file.

GetFileFromFilename ( LuaState luaState, string fileName ) : string

Returns file name and extension.

GetPathFromFilename ( LuaState luaState, string fileName ) : string

Returns the path only from a file's path.

JavascriptSafe ( LuaState luaState, string inputString ) : string

Escapes special characters for JavaScript in a string, making the string safe for inclusion in to JavaScript strings.

Left ( LuaState luaState, string inputString, uint num ) : string

Returns everything left of supplied place of inputString.

NiceSize ( LuaState luaState, uint bytes ) : string

Converts supplied number into bytes.

NiceTime ( LuaState luaState, uint seconds ) : string

Converts supplied number into string.

PatternSafe ( LuaState luaState, string inputString ) : string

Escapes all special characters within a string, making the string safe for inclusion in a Lua pattern.

Replace ( LuaState luaState, string input, string find, string replace ) : string

Replaces all occurrences of the supplied second string.

Right ( LuaState luaState, string inputString, uint num ) : string

Returns the last n-th characters of the string.

SetChar ( LuaState luaState, string inputString, uint index, char replacement ) : string

Sets the character at the specific index of the string.

StartWith ( LuaState luaState, string inputString, string startString ) : bool

Returns whether or not the first string starts with the second.

StripExtension ( LuaState luaState, string fileName ) : string

Removes the extension of a path.

ToMinutesSeconds ( LuaState luaState, uint time ) : string

Returns the given time in "MM:SS" format.

ToMinutesSecondsMilliseconds ( LuaState luaState, double time ) : string

Returns the given time in "MM:SS:MS" format.

Trim ( LuaState luaState, string inputString, string match = " " ) : string

Removes leading and trailing matches of a string.

TrimLeft ( LuaState luaState, string inputString, string match = " " ) : string

Removes leading spaces/characters from a string.

TrimRight ( LuaState luaState, string inputString, string match = " " ) : string

Removes trailing spaces/passed character from a string.

find ( LuaState luaState, string hayStack, string needle, int startPos = 1, bool noPatterns = false ) : int>.Tuple

Attempts to find the specified substring in a string, uses patterns by default.

find ( LuaState luaState, int &start, int &end, string hayStack, string needle, int startPos = 1, bool noPatterns = false ) : void

Attempts to find the specified substring in a string, uses patterns by default.

format ( LuaState luaState, string inputString ) : string

Formats the specified values into the string given.

gsub ( LuaState luaState, string input, string pattern, string replacement, uint maxReplaces = default(uint) ) : uint>.Tuple

This functions main purpose is to replace certain character sequences in a string using patterns.

gsub ( LuaState luaState, string &replaceResult, uint &replaceCount, string input, string pattern, string replacement, uint maxReplaces = default(uint) ) : void

This functions main purpose is to replace certain character sequences in a string using patterns.

len ( LuaState luaState, string inputString ) : uint

Counts the number of characters in the string (length).

lower ( LuaState luaState, string inputString ) : string

Changes any upper-case letters in a inputString to lower-case letters.

match ( LuaState luaState, string inputString, string pattern, int startPosition ) : string

Finds a http://wiki.garrysmod.com/page/Patterns">pattern in a

rep ( LuaState luaState, string inputString, uint repetitions ) : string

Repeats a string by the given value.

reverse ( LuaState luaState, string inputString ) : string

Reverses a string.

sub ( LuaState luaState, string inputString, uint startPos, uint endPos = default(uint) ) : string

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.

upper ( LuaState luaState, string inputString ) : string

Changes any lower-case letters in a string to upper-case letters.

Method Details

@byte() public static method

Returns the given string's characters in their numeric ASCII representation.
public static @byte ( LuaState luaState, string inputString, uint startPos = 1U, uint endPos = 1U ) : byte[]
luaState LuaState Pointer to lua_State struct.
inputString string The string to get the chars from.
startPos uint The first character of the string to get the byte of.
endPos uint The last character of the string to get the byte of.
return byte[]

@char() public static method

Takes the given numerical bytes and converts them to a string.
public static @char ( LuaState luaState ) : string
luaState LuaState Pointer to lua_State struct.
return string

Comma() public static method

Inserts commas for every third digit.
public static Comma ( LuaState luaState, double inputNumber ) : string
luaState LuaState Pointer to lua_State struct.
inputNumber double The input number to commafy.
return string

EndsWith() public static method

Returns whether or not the second passed string matches the end of the first.
public static EndsWith ( LuaState luaState, string inputString, string endString ) : bool
luaState LuaState Pointer to lua_State struct.
inputString string The string whose end is to be checked.
endString string The string to be matched with the end of the first.
return bool

FormattedTime() public static method

Returns the time as a formatted string or as a table if no format is given.
public static FormattedTime ( LuaState luaState, double @float, string format ) : string
luaState LuaState Pointer to lua_State struct.
@float double
format string An optional formatting to use. If no format it specified, a table will be returned instead.
return string

GetExtensionFromFilename() public static method

Returns extension of the file.
public static GetExtensionFromFilename ( LuaState luaState, string fileName ) : string
luaState LuaState Pointer to lua_State struct.
fileName string String e.g. file-path to get the file extensions from.
return string

GetFileFromFilename() public static method

Returns file name and extension.
public static GetFileFromFilename ( LuaState luaState, string fileName ) : string
luaState LuaState Pointer to lua_State struct.
fileName string The string e.g. file-path to get the file-name from.
return string

GetPathFromFilename() public static method

Returns the path only from a file's path.
public static GetPathFromFilename ( LuaState luaState, string fileName ) : string
luaState LuaState Pointer to lua_State struct.
fileName string String to get path from.
return string

JavascriptSafe() public static method

Escapes special characters for JavaScript in a string, making the string safe for inclusion in to JavaScript strings.
public static JavascriptSafe ( LuaState luaState, string inputString ) : string
luaState LuaState Pointer to lua_State struct.
inputString string The string that should be escaped.
return string

Left() public static method

Returns everything left of supplied place of inputString.
public static Left ( LuaState luaState, string inputString, uint num ) : string
luaState LuaState Pointer to lua_State struct.
inputString string The string to extract from.
num uint Amount of chars relative to the beginning (starting from 1).
return string

NiceSize() public static method

Converts supplied number into bytes.
public static NiceSize ( LuaState luaState, uint bytes ) : string
luaState LuaState Pointer to lua_State struct.
bytes uint The number to convert into bytes.
return string

NiceTime() public static method

Converts supplied number into string.
public static NiceTime ( LuaState luaState, uint seconds ) : string
luaState LuaState Pointer to lua_State struct.
seconds uint The number to convert into string.
return string

PatternSafe() public static method

Escapes all special characters within a string, making the string safe for inclusion in a Lua pattern.
public static PatternSafe ( LuaState luaState, string inputString ) : string
luaState LuaState Pointer to lua_State struct.
inputString string The string to be sanitized.
return string

Replace() public static method

Replaces all occurrences of the supplied second string.
public static Replace ( LuaState luaState, string input, string find, string replace ) : string
luaState LuaState Pointer to lua_State struct.
input string The string we are seeking to replace an occurrence(s).
find string What we are seeking to replace.
replace string What to replace find with.
return string

Right() public static method

Returns the last n-th characters of the string.
public static Right ( LuaState luaState, string inputString, uint num ) : string
luaState LuaState Pointer to lua_State struct.
inputString string The string to extract from.
num uint Amount of chars relative to the end (starting from 1).
return string

SetChar() public static method

Sets the character at the specific index of the string.
public static SetChar ( LuaState luaState, string inputString, uint index, char replacement ) : string
luaState LuaState Pointer to lua_State struct.
inputString string The input string.
index uint The character index, 1 is the first from left.
replacement char String to replace with.
return string

StartWith() public static method

Returns whether or not the first string starts with the second.
public static StartWith ( LuaState luaState, string inputString, string startString ) : bool
luaState LuaState Pointer to lua_State struct.
inputString string String to check.
startString string String to check with.
return bool

StripExtension() public static method

Removes the extension of a path.
public static StripExtension ( LuaState luaState, string fileName ) : string
luaState LuaState Pointer to lua_State struct.
fileName string The path to change.
return string

ToMinutesSeconds() public static method

Returns the given time in "MM:SS" format.
public static ToMinutesSeconds ( LuaState luaState, uint time ) : string
luaState LuaState Pointer to lua_State struct.
time uint Time in seconds.
return string

ToMinutesSecondsMilliseconds() public static method

Returns the given time in "MM:SS:MS" format.
public static ToMinutesSecondsMilliseconds ( LuaState luaState, double time ) : string
luaState LuaState Pointer to lua_State struct.
time double Time in seconds.
return string

Trim() public static method

Removes leading and trailing matches of a string.
public static Trim ( LuaState luaState, string inputString, string match = " " ) : string
luaState LuaState Pointer to lua_State struct.
inputString string The string to trim.
match string String to match.
return string

TrimLeft() public static method

Removes leading spaces/characters from a string.
public static TrimLeft ( LuaState luaState, string inputString, string match = " " ) : string
luaState LuaState Pointer to lua_State struct.
inputString string String to trim.
match string Character to remove.
return string

TrimRight() public static method

Removes trailing spaces/passed character from a string.
public static TrimRight ( LuaState luaState, string inputString, string match = " " ) : string
luaState LuaState Pointer to lua_State struct.
inputString string String to remove from.
match string Character to remove.
return string

find() public static method

Attempts to find the specified substring in a string, uses patterns by default.
public static find ( LuaState luaState, string hayStack, string needle, int startPos = 1, bool noPatterns = false ) : int>.Tuple
luaState LuaState Pointer to lua_State struct.
hayStack string The string to search in.
needle string The string to find, can contain patterns if enabled.
startPos int /// The position to start the search from, can be negative start position will be relative to the /// end position. ///
noPatterns bool Set to true to disable patterns.
return int>.Tuple

find() public static method

Attempts to find the specified substring in a string, uses patterns by default.
public static find ( LuaState luaState, int &start, int &end, string hayStack, string needle, int startPos = 1, bool noPatterns = false ) : void
luaState LuaState Pointer to lua_State struct.
start int Starting position of the found text.
end int Ending position of found text.
hayStack string The string to search in.
needle string The string to find, can contain patterns if enabled.
startPos int /// The position to start the search from, can be negative start position will be relative to the /// end position. ///
noPatterns bool Set to true to disable patterns.
return void

format() public static method

Formats the specified values into the string given.
public static format ( LuaState luaState, string inputString ) : string
luaState LuaState Pointer to lua_State struct.
inputString string The string to be formatted. /// /// Follows this format. ///
return string

gsub() public static method

This functions main purpose is to replace certain character sequences in a string using patterns.
public static gsub ( LuaState luaState, string input, string pattern, string replacement, uint maxReplaces = default(uint) ) : uint>.Tuple
luaState LuaState Pointer to lua_State struct.
input string String which should be modified.
pattern string The pattern that defines what should be matched and eventually be replaced.
replacement string /// In case of a string the matches sequence will be replaced with it. /// /// In case of a table, the matched sequence will be used as key and the table will tested for the key, if a value /// exists it will be used as replacement. /// /// In case of a function all matches will be passed as parameters to the function, the return value(s) of the function /// will then be used as replacement. ///
maxReplaces uint Maximum number of replacements to be made.
return uint>.Tuple

gsub() public static method

This functions main purpose is to replace certain character sequences in a string using patterns.
public static gsub ( LuaState luaState, string &replaceResult, uint &replaceCount, string input, string pattern, string replacement, uint maxReplaces = default(uint) ) : void
luaState LuaState Pointer to lua_State struct.
replaceResult string Replaced string.
replaceCount uint Number of replaces.
input string String which should be modified.
pattern string The pattern that defines what should be matched and eventually be replaced.
replacement string /// In case of a string the matches sequence will be replaced with it. /// /// In case of a table, the matched sequence will be used as key and the table will tested for the key, if a value /// exists it will be used as replacement. /// /// In case of a function all matches will be passed as parameters to the function, the return value(s) of the function /// will then be used as replacement. ///
maxReplaces uint Maximum number of replacements to be made.
return void

len() public static method

Counts the number of characters in the string (length).
public static len ( LuaState luaState, string inputString ) : uint
luaState LuaState Pointer to lua_State struct.
inputString string The string to find the length of.
return uint

lower() public static method

Changes any upper-case letters in a inputString to lower-case letters.
public static lower ( LuaState luaState, string inputString ) : string
luaState LuaState Pointer to lua_State struct.
inputString string The string to convert.
return string

match() public static method

Finds a http://wiki.garrysmod.com/page/Patterns">pattern in a
public static match ( LuaState luaState, string inputString, string pattern, int startPosition ) : string
luaState LuaState Pointer to lua_State struct.
inputString string String which should be searched in for matches.
pattern string The pattern that defines what should be matched.
startPosition int /// The start index to start the matching from, can be negative to start the match from a /// position relative to the end. ///
return string

rep() public static method

Repeats a string by the given value.
public static rep ( LuaState luaState, string inputString, uint repetitions ) : string
luaState LuaState Pointer to lua_State struct.
inputString string The string to repeat.
repetitions uint How many times to repeat.
return string

reverse() public static method

Reverses a string.
public static reverse ( LuaState luaState, string inputString ) : string
luaState LuaState Pointer to lua_State struct.
inputString string The string to be reversed.
return string

sub() public static method

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.
public static sub ( LuaState luaState, string inputString, uint startPos, uint endPos = default(uint) ) : string
luaState LuaState Pointer to lua_State struct.
inputString string The string you'll take a sub-string out of.
startPos uint The position of the first character that will be included in the sub-string.
endPos uint The position of the last character to be included in the sub-string.
return string

upper() public static method

Changes any lower-case letters in a string to upper-case letters.
public static upper ( LuaState luaState, string inputString ) : string
luaState LuaState Pointer to lua_State struct.
inputString string The string to convert.
return string