Strings
A string is a sequence of characters (letters, numerical digits, punctuation marks, whitespace, and control characters).
Parsing
strCmp
Compares %one and %two in lexicographical order with case-sensitivity.
Parameters
- string %one, string %twoReturns
-0
if strings %one and %two are equal,-1
if %one precedes %two lexicographically, and1
if %one comes after %two lexicographically.
==> strCmp("Blockland", "Blockland");
0
==> strCmp("Blockland", "Brickland"); // 'l' < 'r'
-1
==> strCmp("Blockland", "Badspot"); // 'l' > 'a'
1
striCmp
Functions the same way as strCmp, but instead compares %one and %two in lexicographical order without case-sensitivity.
Parameters
- string %one, string %twoReturns
-0
if strings %one and %two are equal,-1
if %one precedes %two lexicographically, and1
if %one comes after %two lexicographically.
strPos
Searches for the position of the character(s) %needle in the string, %hay, with case-sensitivity.
Parameters
- string %hay, string %needle, integer %offset (optional)Returns
- The index of %needle in %hay, and-1
if %needle could not be found in %hay.
==> strPos("Test", "t");
3
striPos
Searches for the position of the character(s) %needle in the string, %hay, without case-sensitivity.
Parameters
- string %hay, string %needle, integer %offset (optional)Returns
- The index of %needle in %hay, and-1
if %needle could not be found in %hay.
==> striPos("Test", "t");
0
strLen
Counts the total number of characters in %string.
Parameters
- string %stringReturns
- An integer representing the total number of characters in %string.
==> strLen("Example");
7
getCharCount
Counts the number of times the character %char appears in %string.
Parameters
- string %string, char %charReturns
- An integer representing the number of times %char was found in %string.
==> getCharCount("example", "e");
2
Processing
strChr
Extracts the characters following the first instance of %char in %string, including the %char itself.
Parameters
- string %string, char %charReturns
- String containing the characters located at and after the first appearance of the %char given in %string. If the %char specified could not be found in the %string, the whole string is returned un-modified.
==> strChr("Hello World!", "W");
"World!"
getSubStr
Extracts characters in %string, starting at the index, %start, and ending after %numChars have been read.
Parameters
- string %string, integer %start, integer %numCharsReturns
- String containing the characters in %string located at and after %start, stopping after the amount specified in %numberChars have been read.
==> getSubStr("Hello World!", 0, 5);
"Hello"
strReplace
Replaces all instances of %from in %source with %to.
Parameters
- string %source, string %from, string %toReturns
- Copy of %string which has all of the characters in %from replaced by the characters in %to.
==> strReplace("Blockhead built a town", "town", "castle");
"Blockhead built a castle"
stripChars
Removes all instances of %chars from %string.
Parameters
- string %string, string %charsReturns
- String containing all of the characters, except the ones from %chars, given in %string.
==> stripChars("a1b2c3d4", "1234");
"abcd"
stripMLControlChars
Removes all instances of Torque Markup Language characters from %string.
Parameters
- string %stringReturns
- String containing all of the characters, except TML characters, given in %string.
stripTrailingSpaces
Removes all spaces following the last non-space character in %string
Parameters
- string %stringReturns
- %string with trailing spaces omitted.
==> stripTrailingSpaces("Blockland ");
"Blockland"
ltrim
Removes all whitespace located before the first non-whitespace character in %string
Parameters
- string %stringReturns
- %string with preceding whitespace omitted.
==> ltrim(" 1234");
"1234"
rtrim
Removes all whitespace located after the last non-whitespace character in %string
Parameters
- string %stringReturns
- %string with trailing whitespace omitted.
==> rtrim("1234 ");
"1234"
trim
Removes all whitespace located before and after the first and last non-whitespace character in %string
Parameters
- string %stringReturns
- %string with preceding and trailing whitespace omitted.
==> trim(" 1234 ");
"1234"
strUrp
Converts all lowercase alphabetical characters in %string to their uppercase equivalents.
Parameters
- string %stringReturns
- String containing all characters in %string converted to uppercase.
==> strUrp("the quick brown fox jumps over the lazy dog");
"THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"
strLwr
Converts all uppercase alphabetical characters in %string to their lowercase equivalents.
Parameters
- string %stringReturns
- String containing all characters in %string converted to lowercase.
==> strLwr("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG");
"the quick brown fox jumps over the lazy dog"
expandEscape
Adds another escape level to escape characters.
Parameters
- string %textReturns
- String containing all the characters in %text, with the escaped characters being further escaped.
==> expandEscape("Test\n");
"Test\\n"
collapseEscape
Removes an escape level from the escaped escape characters.
Parameters
- string %textReturns
- String containing all the characters in %text, with the escaped characters being unescaped one level.
==> collapseEscape("Test\\n");
"Test\n"
deTag
Converts a tagged string to a normal string.
Parameters
- string %taggedReturns
- String containing the untagged conversion of %tagged.
==> deTag('leet');
"leet"
Note: You can only detag a string that has already been transmitted to you.
getTag
Gets the tagged number associated with a tagged string
Parameters
- string %taggedReturns
- Integer representing the tagged string, %tagged.
==> getTag('leet');
<somenumber>
Words
getWordCount
Counts the number of words that appear in the string %text.
Parameters
- string %textReturns
- An integer representing the number of words in %string.
==> getWordCount("Hello World");
2
getWord
Captures the word in %string located at the integer index %index.
Parameters
- string %text, integer %indexReturns
- String containing the characters of the word found at %index in %string. Returns an empty string if a word could not be found at the specified %index.
==> getWord("Hello World", 0);
"Hello"
getWords
Captures the word(s) in %string located at the integer index %index, and optionally ending at the integer index %endIndex.
Parameters
- string %text, integer %index, integer %endIndexReturns
- String containing the characters of the word(s) found at and between %index and %endIndex in %string. Returns an empty string if a word/words could not be found at the %index.
==> getWords("Hello World, how are you?", 2, 4);
"how are you?"
setWord
Replaces the word in %string located at the integer index %index with the string, %replace.
Parameters
- string %text, integer %index, string %replaceReturns
- A replica of %string with the word at index replaced with the string, %replace.
==> setWord("Hello World", "Hello", "Hey");
"Hey World"
removeWord
Removes the word in %string located at the integer index %index.
Parameters
- string %text, integer %indexReturns
- A replica of %string with the word at index removed.
==> removeWord("Hello World", "Hello");
"World"
firstWord
Captures the first word that appears in %text.
Parameters
- string %textReturns
- String containing the characters of the first word found in %text.
==> firstWord("Hello World");
"Hello"
restWords
Captures every word in %text except the first.
Parameters
- string %textReturns
- String containing the characters of the word(s) found after the first word in %string. Returns an empty string if there are not any words after the first.
==> restWords("Hello World, how are you?");
"World, how are you?"
Fields
'^' characters represent field delimiters.
getFieldCount
Counts the number of fields that appear in the string %text.
Parameters
- string %textReturns
- An integer representing the number of fields in %string.
==> getFieldCount("Foo^Bar");
2
getField
Captures the field in %string located at the integer index %index.
Parameters
- string %text, integer %indexReturns
- String containing the characters of the field found at %index in %string. Returns an empty string if a field could not be found at the specified %index.
==> getField("Foo^Bar", 0);
"Foo"
getFields
Captures the field(s) in %string located at the integer index %index, and optionally ending at the integer index %endIndex.
Parameters
- string %text, integer %index, integer %endIndexReturns
- String containing the characters of the field(s) found at and between %index and %endIndex in %string. Returns an empty string if a field/fields could not be found at the %index.
==> getFields("Foo^Bar^Baz^Qux", 2, 3);
"Baz^Qux"
setField
Replaces the field in %string located at the integer index %index with the string, %replace.
Parameters
- string %text, integer %index, string %replaceReturns
- A replica of %string with the field at index replaced with the string, %replace.
==> setField("Foo^Bar^Baz^Qux", 0, "Hello");
"Hello^Foo^Baz^Qux"
removeField
Removes the field in %string located at the integer index %index.
Parameters
- string %text, integer %indexReturns
- A replica of %string with the field at index removed.
==> removeField("Foo^Bar^Baz^Qux", 3);
"Foo^Bar^Baz"
firstField
Captures the first field that appears in %text.
Parameters
- string %textReturns
- String containing the characters of the first field found in %text.
==> firstField("Foo^Bar^Baz^Qux");
"Foo"
restFields
Captures every field in %text except the first.
Parameters
- string %textReturns
- String containing the characters of the field(s) found after the first field in %string. Returns an empty string if there are not any fields after the first.
==> restFields("Foo^Bar^Baz^Qux");
"Bar^Baz^Qux"