String Library

From MyGamingTalk
Jump to navigation Jump to search
Script Reference String Library

IsEmpty

Determines whether a string is empty.

Parameters: none

Returns: true or false

Example:

 mystring = "";
 print(mystring.IsEmpty());

Length

Determines the length of a string.

Parameters: none

Returns: the string's length

Example:

 mystring = "";
 print(mystring.Length());

Left

Returns the left count charaters of the string.

Parameters: count

Returns: the left count charaters of the string

Example:

 mystring = "Test me";
 print(mystring.Left(4));

Right

Returns the right count charaters of the string.

Parameters: count

Returns: the right count charaters of the string

Example:

 mystring = "Test me";
 print(mystring.Right(2));

RightAt

Returns the charaters right of and including the given index.

Parameters: index

Returns: the charaters right of and including the given index

Example:

 print("Test me".RightAt(5));

Mid

Mid will return count characters from the start index.

Parameters: startIndex, count

Returns: count characters from startIndex

Example:

 mystring = "Test me";
 print(mystring.Mid(2,2));

Compare

Performs a string comparison.

Parameters: string to compare

Returns: -1 if the this < compare string, 0 if the strings are equal, 1 otherwise

Example:

 mystring = "Test me";
 print(mystring.Compare("test Me"));

CompareNoCase

Performs a string comparison (case insensitive).

Parameters: string to compare

Returns: negative integer if the this < compare string, 0 if the strings are equal, positive integer otherwise

Example:

 print("Test me".CompareNoCase("test ME"));

Upper

Converts a string to upper case.

Parameters: none

Returns: converted string

Example:

 print("Test me".Upper());

Lower

Converts a string to lower case.

Parameters: none

Returns: converted string

Example:

 print("Test me".Lower());

SpanIncluding

Return this string while characters are within the passed string.

Parameters: string charset

Returns: the left part of the string

Example:

 print("Test me".SpanIncluding("esTt"));

SpanExcluding

Return this string while characters are not within the passed string.

Parameters: string charset

Returns: the left part of the string

Example:

 print("Test me".SpanExcluding("acfmx"));

ReplaceCharsInSet

ReplaceCharsInSet will replace all chars in this that are within the charset with the given int char.

Parameters: (char to replace with, string of chars to replace)

Returns: string

Example:

 print("Test me".ReplaceCharsInSet('x',"et"));

Find

Find will find the first occurrence of the passed string within this string.

Parameters: string to find

Returns: index of first occurrence, or -1 if the string was not found

Example:

 mystring = "Test me";
 print(mystring.Find("Me"));

ReverseFind

ReverseFind will find the first occurance of the passed string within this string starting from the right.

Parameters: string to find

Returns: index of first occurrence, or -1 if the string was not found

Example:

 print("Test me".ReverseFind("me"));

Reverse

Reverses the characters of a string.

Parameters: none

Returns: inverted string

Example:

 mystring = "tset";
 print(mystring.Reverse());

GetAt

GetAt will return the char at the given index.

Parameters: index

Returns: char number

Example:

 mystring = "Test";
 print(mystring.GetAt(0)); //prints 84, the char # of "T"

SetAt

Returns string with modified character at offset, or original string if index out of range.

Parameters: (index, char)

Returns: string

Example:

 print("Test me".SetAt(2,'x'));

TrimLeft

TrimLeft will return the string with the chars from the passed char set trimmed from the left.

Parameters: charset; optional (default " \r\n\v\t")

Returns: trimmed string

Example:

 mystring = "  Test";
 print(mystring.TrimLeft());

TrimRight

TrimRight will return the string with the chars from the passed char set trimmed from the right.

Parameters: charset; optional (default " \r\n\v\t")

Returns: trimmed string

Example:

 mystring = "Test  ";
 print(mystring.TrimRight());

GetFilename

GetFilename will return the filename part of a path string incl. extension.

Parameters: none

Returns: filename

Example:

 mystring = "C:\\Program Files\\Omni-Bot\\et\\nav\\test.gm";
 print(mystring.GetFilename());

GetFilenameNoExt

GetFilenameNoExt will return the filename part of a path string without extension.

Parameters: none

Returns: filename

Example:

 mystring = "C:\\Program Files\\Omni-Bot\\et\\nav\\test.gm";
 print(mystring.GetFilenameNoExt());

GetExtension

GetExtension will return the extension part of a path string.

Parameters: none

Returns: extension

Example:

 mystring = "C:\\Program Files\\Omni-Bot\\et\\nav\\test.gm";
 print(mystring.GetExtension());

SetExtension

SetExtension returns a string with the extension changed to the given one.

Parameters: The new extension, with or without the dot. null to remove extension.

Returns: path with new extension

Example:

 mystring = "C:\\Program Files\\Omni-Bot\\et\\nav\\test.gm";
 mystring = mystring.SetExtension(".way");
 print("mystring:",mystring);

GetPath

GetPath will return the file path from a path string.

Parameters: includeSlash (optional, default false)

Returns: path with new extension

Example:

 mystring = "C:\\Program Files\\Omni-Bot\\et\\nav\\test.gm";
 print(mystring.GetPath());
 print(mystring.GetPath(true));

Tokenize

Splits a string into substrings (tokens) at occurrences of the string passed as parameter.

Parameters: String.

Returns: Table of tokens.

Example:

 tokens = "bla, blu, bli".Tokenize(", ");
 foreach (t in tokens)
 {
     print(t);
 }