FieldManip
Functions
string
firstWord(string text)
Return the first word in text.
string
getField(string text, int index)
Extract the field at the given index in the newline and/or tab separated list in text.
int
getFieldCount(string text)
Return the number of newline and/or tab separated fields in text.
string
getFields(string text, int startIndex, int endIndex)
Extract a range of fields from the given startIndex onwards thru endIndex.
string
getRecord(string text, int index)
Extract the record at the given index in the newline-separated list in text.
int
getRecordCount(string text)
Return the number of newline-separated records in text.
string
getRecords(string text, int startIndex, int endIndex)
Extract a range of records from the given startIndex onwards thru endIndex.
string
getToken(string text, string delimiters, int index)
Extract the substring at the given index in the delimiters separated list in text.
int
getTokenCount(string text, string delimiters)
Return the number of delimiters substrings in text.
string
getTokens(string text, string delimiters, int startIndex, int endIndex)
Extract a range of substrings separated by delimiters at the given startIndex onwards thru endIndex.
string
getWord(string text, int index)
Extract the word at the given index in the whitespace-separated list in text.
int
getWordCount(string text)
Return the number of whitespace-separated words in text.
string
getWords(string text, int startIndex, int endIndex)
Extract a range of words from the given startIndex onwards thru endIndex.
string
removeField(string text, int index)
Remove the field in text at the given index.
string
removeRecord(string text, int index)
Remove the record in text at the given index.
string
removeToken(string text, string delimiters, int index)
Remove the substring in text separated by delimiters at the given index.
string
removeWord(string text, int index)
Remove the word in text at the given index.
string
restWords(string text)
Return all but the first word in text.
string
setField(string text, int index, string replacement)
Replace the field in text at the given index with replacement.
string
setRecord(string text, int index, string replacement)
Replace the record in text at the given index with replacement.
string
setToken(string text, string delimiters, int index, string replacement)
Replace the substring in text separated by delimiters at the given index with replacement.
string
setWord(string text, int index, string replacement)
Replace the word in text at the given index with replacement.
Detailed Description
Functions
firstWord(string text)
Return the first word in text.
Parameters:
text | A list of words separated by newlines, spaces, and/or tabs. |
The word at index 0 in text or "" if text is empty.
note:This is equal to @tsexample_nopar getWord( text, 0 )
getField(string text, int index)
Extract the field at the given index in the newline and/or tab separated list in text.
Fields in text must be separated by newlines and/or tabs. Parameters:
text | A list of fields separated by newlines and/or tabs. |
index | The zero-based index of the field to extract. |
The field at the given index or "" if the index is out of range.
getField( "a b" TAB "c d" TAB "e f", 1 ) // Returns "c d"
getFieldCount(string text)
Return the number of newline and/or tab separated fields in text.
Parameters:
text | A list of fields separated by newlines and/or tabs. |
The number of newline and/or tab sepearated elements in text.
getFieldCount( "a b" TAB "c d" TAB "e f" ) // Returns 3
getFields(string text, int startIndex, int endIndex)
Extract a range of fields from the given startIndex onwards thru endIndex.
Fields in text must be separated by newlines and/or tabs. Parameters:
text | A list of fields separated by newlines and/or tabs. |
startIndex | The zero-based index of the first field to extract from text. |
endIndex | The zero-based index of the last field to extract from text. If this is -1, all fields beginning with startIndex are extracted from text. |
A string containing the specified range of fields from text or "" if startIndex is out of range or greater than endIndex.
getFields( "a b" TAB "c d" TAB "e f", 1 ) // Returns "c d" TAB "e f"
getRecord(string text, int index)
Extract the record at the given index in the newline-separated list in text.
Records in text must be separated by newlines. Parameters:
text | A list of records separated by newlines. |
index | The zero-based index of the record to extract. |
The record at the given index or "" if index is out of range.
getRecord( "a b" NL "c d" NL "e f", 1 ) // Returns "c d"
getRecordCount(string text)
Return the number of newline-separated records in text.
Parameters:
text | A list of records separated by newlines. |
The number of newline-sepearated elements in text.
getRecordCount( "a b" NL "c d" NL "e f" ) // Returns 3
getRecords(string text, int startIndex, int endIndex)
Extract a range of records from the given startIndex onwards thru endIndex.
Records in text must be separated by newlines. Parameters:
text | A list of records separated by newlines. |
startIndex | The zero-based index of the first record to extract from text. |
endIndex | The zero-based index of the last record to extract from text. If this is -1, all records beginning with startIndex are extracted from text. |
A string containing the specified range of records from text or "" if startIndex is out of range or greater than endIndex.
getRecords( "a b" NL "c d" NL "e f", 1 ) // Returns "c d" NL "e f"
getToken(string text, string delimiters, int index)
Extract the substring at the given index in the delimiters separated list in text.
Parameters:
text | A delimiters list of substrings. |
delimiters | Character or characters that separate the list of substrings in text. |
index | The zero-based index of the substring to extract. |
The substring at the given index or "" if the index is out of range.
getToken( "a b c d", " ", 2 ) // Returns "c"
getTokenCount(string text, string delimiters)
Return the number of delimiters substrings in text.
Parameters:
text | A delimiters list of substrings. |
delimiters | Character or characters that separate the list of substrings in text. |
The number of delimiters substrings in text.
getTokenCount( "a b c d e", " " ) // Returns 5
getTokens(string text, string delimiters, int startIndex, int endIndex)
Extract a range of substrings separated by delimiters at the given startIndex onwards thru endIndex.
Parameters:
text | A delimiters list of substrings. |
delimiters | Character or characters that separate the list of substrings in text. |
startIndex | The zero-based index of the first substring to extract from text. |
endIndex | The zero-based index of the last substring to extract from text. If this is -1, all words beginning with startIndex are extracted from text. |
A string containing the specified range of substrings from text or "" if startIndex is out of range or greater than endIndex.
getTokens( "a b c d", " ", 1, 2, ) // Returns "b c"
getWord(string text, int index)
Extract the word at the given index in the whitespace-separated list in text.
Words in text must be separated by newlines, spaces, and/or tabs. Parameters:
text | A whitespace-separated list of words. |
index | The zero-based index of the word to extract. |
The word at the given index or "" if the index is out of range.
getWord( "a b c", 1 ) // Returns "b"
getWordCount(string text)
Return the number of whitespace-separated words in text.
Words in text must be separated by newlines, spaces, and/or tabs. Parameters:
text | A whitespace-separated list of words. |
The number of whitespace-separated words in text.
getWordCount( "a b c d e" ) // Returns 5
getWords(string text, int startIndex, int endIndex)
Extract a range of words from the given startIndex onwards thru endIndex.
Words in text must be separated by newlines, spaces, and/or tabs. Parameters:
text | A whitespace-separated list of words. |
startIndex | The zero-based index of the first word to extract from text. |
endIndex | The zero-based index of the last word to extract from text. If this is -1, all words beginning with startIndex are extracted from text. |
A string containing the specified range of words from text or "" if startIndex is out of range or greater than endIndex.
getWords( "a b c d", 1, 2, ) // Returns "b c"
removeField(string text, int index)
Remove the field in text at the given index.
Fields in text must be separated by newlines and/or tabs. Parameters:
text | A list of fields separated by newlines and/or tabs. |
index | The zero-based index of the field in text. |
A new string with the field at the given index removed or the original string if index is out of range.
removeField( "a b" TAB "c d" TAB "e f", 1 ) // Returns "a b" TAB "e f"
removeRecord(string text, int index)
Remove the record in text at the given index.
Records in text must be separated by newlines. Parameters:
text | A list of records separated by newlines. |
index | The zero-based index of the record in text. |
A new string with the record at the given index removed or the original string if index is out of range.
removeRecord( "a b" NL "c d" NL "e f", 1 ) // Returns "a b" NL "e f"
removeToken(string text, string delimiters, int index)
Remove the substring in text separated by delimiters at the given index.
Parameters:
text | A delimiters list of substrings. |
delimiters | Character or characters that separate the list of substrings in text. |
index | The zero-based index of the word in text. |
A new string with the substring at the given index removed or the original string if index is out of range.
removeToken( "a b c d", " ", 2 ) // Returns "a b d"
removeWord(string text, int index)
Remove the word in text at the given index.
Words in text must be separated by newlines, spaces, and/or tabs. Parameters:
text | A whitespace-separated list of words. |
index | The zero-based index of the word in text. |
A new string with the word at the given index removed or the original string if index is out of range.
removeWord( "a b c d", 2 ) // Returns "a b d"
restWords(string text)
Return all but the first word in text.
Parameters:
text | A list of words separated by newlines, spaces, and/or tabs. |
text with the first word removed.
note:This is equal to @tsexample_nopar getWords( text, 1 )
setField(string text, int index, string replacement)
Replace the field in text at the given index with replacement.
Fields in text must be separated by newlines and/or tabs. Parameters:
text | A list of fields separated by newlines and/or tabs. |
index | The zero-based index of the field to replace. |
replacement | The string with which to replace the field. |
A new string with the field at the given index replaced by replacement or the original string if index is out of range.
setField( "a b" TAB "c d" TAB "e f", 1, "g h" ) // Returns "a b" TAB "g h" TAB "e f"
setRecord(string text, int index, string replacement)
Replace the record in text at the given index with replacement.
Records in text must be separated by newlines. Parameters:
text | A list of records separated by newlines. |
index | The zero-based index of the record to replace. |
replacement | The string with which to replace the record. |
A new string with the record at the given index replaced by replacement or the original string if index is out of range.
setRecord( "a b" NL "c d" NL "e f", 1, "g h" ) // Returns "a b" NL "g h" NL "e f"
setToken(string text, string delimiters, int index, string replacement)
Replace the substring in text separated by delimiters at the given index with replacement.
Parameters:
text | A delimiters list of substrings. |
delimiters | Character or characters that separate the list of substrings in text. |
index | The zero-based index of the substring to replace. |
replacement | The string with which to replace the substring. |
A new string with the substring at the given index replaced by replacement or the original string if index is out of range.
setToken( "a b c d", " ", 2, "f" ) // Returns "a b f d"
setWord(string text, int index, string replacement)
Replace the word in text at the given index with replacement.
Words in text must be separated by newlines, spaces, and/or tabs. Parameters:
text | A whitespace-separated list of words. |
index | The zero-based index of the word to replace. |
replacement | The string with which to replace the word. |
A new string with the word at the given index replaced by replacement or the original string if index is out of range.
setWord( "a b c d", 2, "f" ) // Returns "a b f d"