TorqueScript Reference
Functions
String Fields

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

◆ firstWord()

String firstWord ( sourceString  )

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

Parameters
sourceStringA 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

◆ getField()

String getField ( sourceString  ,
index   
)

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

Parameters
sourceStringA 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

◆ getFieldCount()

Integer getFieldCount ( sourceString  )

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

Parameters
sourceStringA string containing one or more fields.
Returns
Returns number of fields in sourceString or 0 if no fields are present

◆ getFields()

String getFields ( sourceString  ,
index  [, endindex] 
)

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

Parameters
sourceStringA string containing one or more fields.
indexThe index of the first field to retrieve.
endindexThe 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

◆ getRecord()

String getRecord ( sourceString  ,
index   
)

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

Parameters
sourceStringA 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

◆ getRecordCount()

Integer getRecordCount ( sourceString  )

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

Parameters
sourceStringA string containing one or more records.
Returns
Returns number of records in sourceString or 0 if no records are present

◆ getRecords()

String getRecords ( sourceString  ,
index  [, endindex] 
)

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

Parameters
sourceStringA string containing one or more records.
indexThe index of the first record to retrieve.
endindexThe 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

◆ getUnit()

String getUnit ( sourceString  ,
index  ,
separator   
)

◆ getUnitCount()

Integer getUnitCount ( sourceString  ,
separator   
)

◆ getWord()

String getWord ( sourceString  ,
index   
)

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

Parameters
sourceStringA 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

◆ getWordCount()

Integer getWordCount ( sourceString  )

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

Parameters
sourceStringA string containing one or more words.
Returns
Returns number of words in sourceString or 0 if no words are present

◆ getWords()

String getWords ( sourceString  ,
index  [, endindex] 
)

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

Parameters
sourceStringA string containing one or more words.
indexThe index of the first word to retrieve.
endindexThe 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

◆ NextToken()

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 \George. Then, depending on where this function is called, \George\ will become a local (George), or a global ($George) variable. If this function is called within a function or method definition, \George\ 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), \George\ 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
tokenListThe string containing token(s).
tokenVarThe 'name' of the variable to store the token in.
delimeterThe 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.

◆ removeField()

String removeField ( sourceString  ,
index   
)

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

Parameters
sourceStringA string containing one or more fields.
indexThe 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

◆ removeRecord()

String removeRecord ( sourceString  ,
index   
)

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

Parameters
sourceStringA string containing one or more records.
indexThe 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

◆ removeWord()

String removeWord ( sourceString  ,
index   
)

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

Parameters
sourceStringA string containing one or more words.
indexThe 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

◆ restWords()

String restWords ( sourceString  )

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

Parameters
sourceStringA 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

◆ setField()

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
sourceStringA string containing one or more fields.
indexThe index of the field to remove.
replaceThe 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

◆ setRecord()

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
sourceStringA string containing one or more records.
indexThe index of the record to remove.
replaceThe 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

◆ setUnit()

String setUnit ( sourceString  ,
index  ,
replace  ,
separator   
)

◆ setWord()

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
sourceStringA string containing one or more words.
indexThe index of the word to remove.
replaceThe 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