Programmer Guide/Command Reference/SUBSTR: Difference between revisions

From STX Wiki
Jump to navigationJump to search
m (1 revision: Initial import)
No edit summary
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
==SUBSTR==
{{PG_StringCommands}}
<var>var</var> := SUBSTR <var>string</var> [ <var>skip_count</var> [ <var>length</var> ]]


<code>var := SUBSTR <var>string</var> [ <var>start</var> [ <var>length</var> ]]</code>
The {{STX}} <code>SUBSTR</code> command extracts a substring from its first argument, <var>string</var>. The start of the substring to extract is denoted by the second parameter <var>skip_count</var>, denoting the number of characters ''to skip''.


-> var = 'string[start .. start+length-1]'
The length of the substring to extract is denoted by the third parameter, <var>length</var>. If you supply a negative number for <var>length</var>, its absolute value will be used, ''and'' <var>skip_count</var> will start at the ''end'' of the string. Isn't {{STx}} a splendid beast!
 
Get a substring of the string <var>string</var>. If no length is specified all characters from <var>start</var> to the end of the string are copied to <code>var</code>. If neither


;<var>string</var>
;<var>string</var>
:The string from which to retrieve the substring.
:The string from which to retrieve the substring.
 
;<var>skip_count</var>
;<var>start</var>
:by denoting the number of characters to skip from the beginning (<var>length</var>&ge;0) or from the end of the string (<var>length</var>&lt;0), <var>skip_count</var> indicates where to start extracting the substring. The default value is <code>0</code>.
 
:The zero-based index of the first character of the substring. The default value is <code>0</code>.
 
;<var>length</var>
;<var>length</var>
:Its absolute value determines the length of the substring to extract. If <var>length</var> is less than zero, <var>skip_count</var> characters will be skipped from the ''end'' of the string; otherwise, they will be skipped from the ''beginning'' of the string. If omitted, the "remaining" part of the string will be extracted.


:The length of the substring. If length is not specified then the length of the string minus <var>start</var> is used.
# skip 1 character, returning 'bcd'
 
<var>#str</var> := substr 'abcd' 1
Remove the first character of a string.
 
# skip 2 characters, returning 'cd'
<pre>
<var>#str</var> := substr 'abcd' 2
#str := substr '$#str' 1
</pre>
# skip 1 character, request 2 characters - returning 'bc'
<var>#str</var> := substr 'abcd' 1 2
# skip 2 character from the end, request 1 character, returning 'b'
<var>#str</var> := substr 'abcd' 2 -1

Latest revision as of 10:19, 4 March 2016

var := SUBSTR string [ skip_count [ length ]]

The STx SUBSTR command extracts a substring from its first argument, string. The start of the substring to extract is denoted by the second parameter skip_count, denoting the number of characters to skip.

The length of the substring to extract is denoted by the third parameter, length. If you supply a negative number for length, its absolute value will be used, and skip_count will start at the end of the string. Isn't STx a splendid beast!

string
The string from which to retrieve the substring.
skip_count
by denoting the number of characters to skip from the beginning (length≥0) or from the end of the string (length<0), skip_count indicates where to start extracting the substring. The default value is 0.
length
Its absolute value determines the length of the substring to extract. If length is less than zero, skip_count characters will be skipped from the end of the string; otherwise, they will be skipped from the beginning of the string. If omitted, the "remaining" part of the string will be extracted.
# skip 1 character, returning 'bcd'
#str := substr 'abcd' 1

# skip 2 characters, returning 'cd'
#str := substr 'abcd' 2

# skip 1 character, request 2 characters - returning 'bc'
#str := substr 'abcd' 1 2

# skip 2 character from the end, request 1 character, returning 'b'
#str := substr 'abcd' 2 -1

Navigation menu

Personal tools