Programmer Guide/Command Reference/SUBSTR: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
Line 4: Line 4:
  var := SUBSTR <var>string</var> [ <var>skip_count</var> [ <var>length</var> ]]
  var := SUBSTR <var>string</var> [ <var>skip_count</var> [ <var>length</var> ]]


The <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</code>, denoting the number of characters to skip.
The <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.


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.
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.

Revision as of 15:57, 3 July 2013

SUBSTR

var := SUBSTR string [ skip_count [ length ]]

The 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.

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 1 character from the end, request 2 characters, returning 'ab'
#str := substr 'abcd' 1 -2

Navigation menu

Personal tools