Substring (StringTokenizer function): Difference between revisions
Jump to navigation
Jump to search
m (1 revision) |
m (→Syntax terms) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 12: | Line 12: | ||
<tr><th>%string</th> | <tr><th>%string</th> | ||
<td>A string variable to contain the returned substring. </td></tr> | <td>A string variable to contain the returned substring. </td></tr> | ||
<tr><th>stringTokenizer</th> | <tr><th>stringTokenizer</th> | ||
<td>A <var>StringTokenizer</var> object expression. </td></tr> | <td>A <var>StringTokenizer</var> object expression. </td></tr> | ||
<tr><th>position</th> | <tr><th>position</th> | ||
<td>The starting byte number in the tokenizing string to return. </td></tr> | <td>The starting byte number in the tokenizing string to return. </td></tr> | ||
<tr><th>length</th> | <tr><th>length</th> | ||
<td>The number of bytes to return. If the tokenizing string has fewer characters than the requested bytes (starting at | <td>The number of bytes to return. If the tokenizing string has fewer characters than the requested bytes (starting at <var class="term">position</var>), it is either padded to the requested length, or the entire tokenizing string starting at the start position is returned with no padding, depending on the value of the <var>Pad</var> parameter. </td></tr> | ||
<tr><th><var>Pad</var></th> | <tr><th><var>Pad</var></th> | ||
<td>The character used to pad the result substring on the right if the result is shorter than the requested length. | <td>The character used to pad the result substring on the right if the result is shorter than the requested length. <var class="term">c</var> defaults to the null string, which means no padding is done. <var>Pad</var> is a [[Notation conventions for methods#Named parameters|name required]] parameter.</td></tr> | ||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul> | ||
<li>The length must be a non-negative number. | <li>The <var class="term">length</var> value must be a non-negative number. | ||
A negative number results in request cancellation. | A negative number results in request cancellation. | ||
<li>The | |||
<li>The <var>Pad</var> argument must be either the null string or a single character. | |||
A longer value results | A longer value results | ||
in request cancellation in <var class="product">Sirius Mods</var> version 7.2 and in a compilation | in request cancellation in <var class="product">Sirius Mods</var> version 7.2 and in a compilation | ||
error in <var class="product">Sirius Mods</var> 7.3 and higher. | error in <var class="product">Sirius Mods</var> 7.3 and higher. | ||
</ul> | </ul> | ||
==Examples== | ==Examples== | ||
The following request prints | The following request prints <code>nizer Substring example!!!!!</code>: | ||
<p class="code">begin | <p class="code">begin | ||
%tok is object stringtokenizer | %tok is object stringtokenizer | ||
Line 39: | Line 45: | ||
%tok:string = 'a tokenizer Substring example' | %tok:string = 'a tokenizer Substring example' | ||
%sub = %tok:substring(7, 28, pad='!') | %sub = %tok:substring(7, 28, pad='!') | ||
printText {~} is {%tok:substring(7, 28, pad='!')} | [[Targeted Text statements|printText]] {~} is {%tok:substring(7, 28, pad='!')} | ||
end | end | ||
</p> | </p> |
Latest revision as of 20:56, 15 November 2012
Specified substring within tokenizing string (StringTokenizer class)
This function returns a substring
that is a specified length and starts at a specific position in the
tokenizing string.
The substring may be padded on the right.
Syntax
%string = stringTokenizer:Substring( position, length, [Pad= c])
Syntax terms
%string | A string variable to contain the returned substring. |
---|---|
stringTokenizer | A StringTokenizer object expression. |
position | The starting byte number in the tokenizing string to return. |
length | The number of bytes to return. If the tokenizing string has fewer characters than the requested bytes (starting at position), it is either padded to the requested length, or the entire tokenizing string starting at the start position is returned with no padding, depending on the value of the Pad parameter. |
Pad | The character used to pad the result substring on the right if the result is shorter than the requested length. c defaults to the null string, which means no padding is done. Pad is a name required parameter. |
Usage notes
- The length value must be a non-negative number. A negative number results in request cancellation.
- The Pad argument must be either the null string or a single character. A longer value results in request cancellation in Sirius Mods version 7.2 and in a compilation error in Sirius Mods 7.3 and higher.
Examples
The following request prints nizer Substring example!!!!!
:
begin %tok is object stringtokenizer %tok = new %tok:string = 'a tokenizer Substring example' %sub = %tok:substring(7, 28, pad='!') printText {~} is {%tok:substring(7, 28, pad='!')} end