TorqueScript Reference

- Main Page
- Related Pages
- Modules
- Classes

Functions
String Fields
Function Categories

## Functions
String | firstWord (sourceString)
String | getField (sourceString, index)
Integer | getFieldCount (sourceString)
String | getFields (sourceString, index[, endindex])
String | getRecord (sourceString, index)
Integer | getRecordCount (sourceString)
String | getRecords (sourceString, index[, endindex])
String | getUnit (sourceString, index, separator)
Integer | getUnitCount (sourceString, separator)
String | getWord (sourceString, index)
Integer | getWordCount (sourceString)
String | getWords (sourceString, index[, endindex])
String | NextToken (tokenList, tokenVar, delimeter)
String | removeField (sourceString, index)
String | removeRecord (sourceString, index)
String | removeWord (sourceString, index)
String | restWords (sourceString)
String | setField (sourceString, index, replace)
String | setRecord (sourceString, index, replace)
String | setUnit (sourceString, index, replace, separator)
String | setWord (sourceString, index, replace)

## Detailed Description

## Function Documentation

String firstWord | ( | sourceString |  | ) |

Use the firstWord function to retrieve the first word found in sourceString.

Parameters

  sourceString | A string containing one or more words.

Returns
  Returns the first word found in sourceString, or a NULL string, if no words are found.

See also
  restWords

String getField | ( | sourceString | ,
|  | index |
| ) |  |

Use the getField function to get the field at index in sourceString.

Parameters

  sourceString | A string containing one or more fields.

Returns
  Returns field at index in sourceString, or null string if no field exists at that index.

See also
  getFields, setField

Integer getFieldCount | ( | sourceString |  | ) |

Use the getFieldCount function to get the number of fields in sourceString.

Parameters

  sourceString | A string containing one or more fields.

Returns
  Returns number of fields in sourceString or 0 if no fields are present

String getFields | ( | sourceString | ,
|  | index | [, endindex]
| ) |  |

Use the getFields function to retrieve a set of fields from a sourceString.

Parameters

  sourceString | A string containing one or more fields.
  index | The index of the first field to retrieve.
  endindex | The index of the final field to retrieve.

Returns
  Returns all fields (separated by current delimiter) from sourceString, starting at index and ending at endIndex or end of string, whichever comes first. If no endIndex is specified, all remaining fields are returned.

See also
  getField, setField

String getRecord | ( | sourceString | ,
|  | index |
| ) |  |

Use the getRecord function to get the record at index in sourceString.

Parameters

  sourceString | A string containing one or more records.

Returns
  Returns record at index in sourceString, or NULL string if no record exists at that index.

See also
  getRecords, setRecord

Integer getRecordCount | ( | sourceString |  | ) |

Use the getRecordCount function to get the number of records in sourceString.

Parameters

  sourceString | A string containing one or more records.

Returns
  Returns number of records in sourceString or 0 if no records are present

String getRecords | ( | sourceString | ,
|  | index | [, endindex]
| ) |  |

Use the getRecords function to retrieve a set of records from a sourceString.

Parameters

  sourceString | A string containing one or more records.
  index | The index of the first record to retrieve.
  endindex | The index of the final record to retrieve.

Returns
  Returns all records (separated by current delimiter) from sourceString, starting at index and ending at endIndex or end of string, whichever comes first. If no endIndex is specified, all remaining records are returned.

See also
  getRecord, setRecord

String getUnit | ( | sourceString | ,
|  | index | ,
|  | separator |
| ) |  |

Integer getUnitCount | ( | sourceString | ,
|  | separator |
| ) |  |

String getWord | ( | sourceString | ,
|  | index |
| ) |  |

Use the getWord function to get the word at index in sourceString.

Parameters

  sourceString | A string containing one or more words.

Returns
  Returns word at index in sourceString, or null string if no word exists at that index.

See also
  getWords, setWord

Integer getWordCount | ( | sourceString |  | ) |

Use the getWordCount function to get the number of words in sourceString.

Parameters

  sourceString | A string containing one or more words.

Returns
  Returns number of words in sourceString or 0 if no words are present

String getWords | ( | sourceString | ,
|  | index | [, endindex]
| ) |  |

Use the getWords function to retrieve a set of words from a sourceString.

Parameters

  sourceString | A string containing one or more words.
  index | The index of the first word to retrieve.
  endindex | The index of the final word to retrieve.

Returns
  Returns all words (separated by current delimiter) from sourceString, starting at index and ending at endIndex or end of string, whichever comes first. If no endIndex is specified, all remaining words are returned.

See also
  getWord, setWord

String NextToken | ( | tokenList | ,
|  | tokenVar | ,
|  | delimeter |
| ) |  |

Use the nextToken function to get the first token found in tokenList, where tokens are separated by the character(s) specified in delimeter. The token itself is stored in a variable whose name is specified in tokenVar. This function provides complex power in a simple package. Please read the notes below, they are very important. This function is scope-smart. That is, when we specify the name of the variable to store a token in by passing a value in tokenVar, we do not include either a local symbol (%), or a global symbol ($). We just pass in an un-adorned name, let's say . Then, depending on where this function is called, \ will become a local (George), or a global ($George) variable. If this function is called within a function or method definition, \ will be local (George). If this function is called from the file-scope (executed as part of a file and not within the scope of a function or method), \ will become a global ($George). There is one additional special case. If you attempt to use this from the console command line, the token will vaporize and no variable will be created

Parameters

  tokenList | The string containing token(s).
  tokenVar | The 'name' of the variable to store the token in.
  delimeter | The character(s) to use as a delimeter. A delimeter may be a single character, or a sequence of characters.

Returns
  Returns a copy of tokenList, less the first token and the first delimiter. If there are no more tokens, a NULL string is returned.

String removeField | ( | sourceString | ,
|  | index |
| ) |  |

Use the removeField function to remove a single indexed field from a sourceString.

Parameters

  sourceString | A string containing one or more fields.
  index | The index of the field to remove.

Returns
  Returns sourceString minus the removed field. If the index is greater than the number of fields in sourceString, the original string is returned.

See also
  setField

String removeRecord | ( | sourceString | ,
|  | index |
| ) |  |

Use the removeRecord function to remove a single indexed record from a sourceString.

Parameters

  sourceString | A string containing one or more records.
  index | The index of the record to remove.

Returns
  Returns sourceString minus the removed record. If the index is greater than the number of records in sourceString, the original string is returned.

See also
  setRecord

String removeWord | ( | sourceString | ,
|  | index |
| ) |  |

Use the removeWord function to remove a single indexed word from a sourceString.

Parameters

  sourceString | A string containing one or more words.
  index | The index of the word to remove.

Returns
  Returns sourceString minus the removed word. If the index is greater than the number of words in sourceString, the original string is returned.

See also
  setWord

String restWords | ( | sourceString |  | ) |

Use the restWords function to retrieve all words after the first word in sourceString.

Parameters

  sourceString | A string containing one or more words.

Returns
  Returns a string containing all the words after the first word found in sourceString, or a NULL string if no words remain after the first word (or if no words at all remain).

See also
  firstWord

String setField | ( | sourceString | ,
|  | index | ,
|  | replace |
| ) |  |

Use the setField function to replace an existing field with a new field(s), or to add field(s) to a string..

Parameters

  sourceString | A string containing one or more fields.
  index | The index of the field to remove.
  replace | The new field(s) to replace the field at index with.

Returns
  There are multiple return cases:- In the first case, a simple one-to-one replacement, the field at index in sourceString will be replaced with the value in replace, and the new string will be returned.- In the first case, a multi-to-one replacement, the field at index in sourceString will be replaced with the value in replace, which can be two or more fields, and the new string will be returned.- In the thrid and final case, new records, empty or filled, can be appended to the end of sourceString. If index is beyond the end of the sourceString, that is, the index is greater than the total count of fields in sourceString, the requisite number of empty (null-string) fields will be appended to the end of sourceString and the value in replace will be appended to the end of this new string. This entire resultant string will be returned.

See also
  getField, getFields, removeField

String setRecord | ( | sourceString | ,
|  | index | ,
|  | replace |
| ) |  |

Use the setRecord function to replace an existing record with a new record(s), or to add record(s) to a string..

Parameters

  sourceString | A string containing one or more records.
  index | The index of the record to remove.
  replace | The new record(s) to replace the record at index with.

Returns
  There are multiple return cases:- In the first case, a simple one-to-one replacement, the record at index in sourceString will be replaced with the value in replace, and the new string will be returned.- In the first case, a multi-to-one replacement, the record at index in sourceString will be replaced with the value in replace, which can be two or more records, and the new string will be returned.- In the thrid and final case, new records, empty or filled, can be appended to the end of sourceString. If index is beyond the end of the sourceString, that is, the index is greater than the total count of records in sourceString, the requisite number of empty (null-string) records will be appended to the end of sourceString and the value in replace will be appended to the end of this new string. This entire resultant string will be returned.

See also
  getRecord, getRecords, removeRecord

String setUnit | ( | sourceString | ,
|  | index | ,
|  | replace | ,
|  | separator |
| ) |  |

String setWord | ( | sourceString | ,
|  | index | ,
|  | replace |
| ) |  |

Use the setWord function to replace an existing word with a new word(s), or to add word(s) to a string..

Parameters

  sourceString | A string containing one or more words.
  index | The index of the word to remove.
  replace | The new word(s) to replace the word at index with.

Returns
  There are multiple return cases:- In the first case, a simple one-to-one replacement, the word at index in sourceString will be replaced with the value in replace, and the new string will be returned.- In the first case, a multi-to-one replacement, the word at index in sourceString will be replaced with the value in replace, which can be two or more words, and the new string will be returned.- In the third and final case, new records, empty or filled, can be appended to the end of sourceString. If index is beyond the end of the sourceString, that is, the index is greater than the total count of words in sourceString, the requisite number of empty (null-string) words will be appended to the end of sourceString and the value in replace will be appended to the end of this new string. This entire resultant string will be returned.

See also
  getWord, getWords, removeWord