TorqueScript Reference

- Main Page
- Related Pages
- Modules
- Classes

Functions
String
Function Categories

## Functions
String | getSubStr (sourceString, start, count)
String | ltrim (sourceString)
String | rtrim (sourceString)
String | strchr (sourceString, char)
Integer | strcmp (string1, string2)
Integer | stricmp (string1, string2)
String | stripChars (sourceString, chars)
String | stripColorCodes (stringtoStrip)
String | stripTrailingSpaces (string)
Integer | strlen (string)
String | strlwr (sourceString)
Integer | strpos (sourceString, searchString, [offset]?)
String | strrchr (sourceString, char)
String | strreplace (sourceString, from, to)
Integer | strstr (sourceString, searchString)
String | strupr (sourceString)
String | trim (sourceString)

## Detailed Description

## Function Documentation

String getSubStr | ( | sourceString | ,
|  | start | ,
|  | count |
| ) |  |

Use the getSubStr function to get a sub-string of sourceString, starting at character index start and ending at character index start + count, or the end-of-string, which ever comes first. If start + count is greater than the length of sourceString, the extraction will return a string shorter than count.

Parameters

  sourceString | The string from which to extract a sub-string.
  start | The character index at which the extraction starts.
  count | The length of the sub-string to extract.

Returns
  Returns a string made up of the character at start in sourceString and ending at the end of the original sourceString, or start + count, whichever comes first.

See also
  strchr

String ltrim | ( | sourceString |  | ) |

Use the ltrim function to strip the leading white space from sourceString. White space is any character in this set: spaces, TABs, and NULL strings.

Parameters

  sourceString | The string to be trimmed.

Returns
  Returns sourceString with all the leading white spaces removed.

See also
  stripChars, stripMLControlChars, stripTrailingSpaces, rtrim, trim

String rtrim | ( | sourceString |  | ) |

Use the rtrim function to strip the trailing white space from sourceString. White space is any character in this set: spaces, TABs, and NULL strings.

Parameters

  sourceString | The string to be trimmed.

Returns
  Returns sourceString with all the trailing white spaces removed.

See also
  stripChars, stripMLControlChars, stripTrailingSpaces, ltrim, trim

String strchr | ( | sourceString | ,
|  | char |
| ) |  |

Use the strchr function to extract a sub-string of sourceString, where the sub-string is equal to the first occurence of char in sourceString followed by the remainder of sourceString.

Parameters

  sourceString | The string from which to extract a sub-string.
  char | The character to search for in sourceString.

Returns
  Returns a string composed of first instance of char in sourceString, and all of the characters after it. If char is not found, a NULL string is returned.

See also
  getSubStr

Integer strcmp | ( | string1 | ,
|  | string2 |
| ) |  |

Use the strcmp function to do a lexicographic case sensitive string comparison between string1 and string2.

Parameters

  string1 | String to be compared to string2.
  string2 | String to be compared to string1.

Returns
  Returns a numeric value: <-1 (string1 is less than string2, including case), 0 (string1 is equal to string2, including case), 1 (string1 is greater than string2, including case)>.

See also
  see stricmp, strstr

Integer stricmp | ( | string1 | ,
|  | string2 |
| ) |  |

Use the stricmp function to do a lexicographic case in-sensitive string comparison between string1 and string2.

Parameters

  string1 | String to be compared to string2.
  string2 | String to be compared to string1.

Returns
  Returns a numeric value: <-1 (string1 is less than string2, ignoring case), 0 (string1 is equal to string2, ignoring case), 1 (string1 is greater than string2, ignoring case)>.

See also
  see strcmp, strstr

String stripChars | ( | sourceString | ,
|  | chars |
| ) |  |

Use the stripChars function to remove chars from sourceString.

Parameters

  sourceString | The string to be modified.
  chars | The character or characters to search for and remove.

Returns
  Returns a copy of sourceString, from which all instances of chars have been removed. This may be the original sourceString, if chars was not found.

See also
  stripMLControlChars, stripTrailingSpaces

String stripColorCodes | ( | stringtoStrip |  | ) |

remove TorqueML color codes from the string.

Parameters

  stringtoString | The string from which to remove TorqueML color codes

Returns
  A string consisting of the original string minus color codes

String stripTrailingSpaces | ( | string |  | ) |

Removes all spaces after the final

Parameters

  string | from which to remove trailing spaces

Returns
  the source string minus trailing spaces

Integer strlen | ( | string |  | ) |

Use the strlen function to determine how many characters there are in string.

Parameters

  string | The string to count characters for.

Returns
  Returns the number of characters in string, or 0 if string is invalid or a NULL string

String strlwr | ( | sourceString |  | ) |

Use the strlwr function to convert all alpha characters in sourceString to lower-case equivalents.

Parameters

  sourceString | The string to be modified.

Returns
  Returns a copy of sourceString in which all upper-case characters have been converted to lower-case letters.

See also
  strupr

Integer strpos | ( | sourceString | ,
|  | searchString | ,
|  | [offset] ? |
| ) |  |

Use the strPos function to locate the first instance of searchString in sourceString, starting at character 0, or at an optional offset.

Parameters

  sourceString | The string in which to search for searchString.
  searchString | The string for which to search for in sourceString.
  offset | An optional non-negative integer value representing the character offset within sourceString at which to begin the search.

Returns
  Returns a numeric character index representing the postion in sourceString at which searchString was found, or -1 to indicate that no instance of searchString was found.

See also
  strstr

String strrchr | ( | sourceString | ,
|  | char |
| ) |  |

strrchr searches the sourceString for the last occurance of the giuven char

Parameters

  sourceString | The string to search

Returns
  Either a string consisting of the given string from the last occurance of the given char on or an empty string if not found

String strreplace | ( | sourceString | ,
|  | from | ,
|  | to |
| ) |  |

Use the strreplace function to replace every instance of from in sourceString with to. This function is case-sensitive and only does exact matching

Parameters

  sourceString | The string to do replacement operations on.
  from | The old value to be replaced.
  to | The new value to replace old values with.

Returns
  Returns a new version of sourceString in which every instance of the value in from was replaced with the value in to.

Integer strstr | ( | sourceString | ,
|  | searchString |
| ) |  |

Use the strstr function to locate the first instance of searchString in sourceString.

Parameters

  sourceString | The string in which to search for searchString.
  searchString | The string for which to search for in sourceString.

Returns
  Returns a numeric character index representing the position in sourceString at which searchString was found, or -1 to indicate that no instance of searchString was found.

See also
  strpos

String strupr | ( | sourceString |  | ) |

Use the strupr function to convert all alpha characters in sourceString to upper-case equivalents.

Parameters

  sourceString | The string to be modified.

Returns
  Returns a copy of sourceString in which all lower-case characters have been converted to upper-case letters.

See also
  strlwr

String trim | ( | sourceString |  | ) |

Use the trim function to strip the leading and trailing white space from sourceString. White space is any character in this set: spaces, TABs, and NULL strings.

Parameters

  sourceString | The string to be trimmed.

Returns
  Returns sourceString with all the leading and trailing white spaces removed.

See also
  stripChars, stripMLControlChars, stripTrailingSpaces, ltrim, rtrim