Table of contents
CSPICE_NEXTWD returns the next word in a given character string, and
left justify the rest of the string.
Given:
string the input string to be parsed.
help, string
STRING = Scalar
Each word of this string is a maximal sequence of consecutive
non-blank characters.
the call:
cspice_nextwd, string, next, rest
returns:
next the first word in `string'.
help, next
STRING = Scalar
It is called the "next" word because cspice_nextwd is
typically called repeatedly to find the words of the input
string in left-to-right order. A word is a maximal sequence
of consecutive non-blank characters. `next' is always
returned left-justified.
If `string' is blank or empty, `next' is empty.
`next' may NOT overwrite `string'.
rest the remaining part of `string', left-justified after the
removal of `next'.
help, rest
STRING = Scalar
`rest' may overwrite `string'.
None.
Any numerical results shown for this example may differ between
platforms as the results depend on the SPICE kernels used as input
and the machine specific arithmetic implementation.
1) Given a character string, get the sequence of words within.
Example code begins here.
PRO nextwd_ex1
rest = ' Now is the time, for all good men to come.'
print, format='(A)', 'Next Rest of the string'
print, format='(A)', '----- ---' + $
'---------------------------------------'
while ( ~ cspice_eqstr( rest, '' ) ) do begin
string = rest
cspice_nextwd, string, next, rest
print, format='(A-5,2X,A)', next, rest
endwhile
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
Next Rest of the string
----- ------------------------------------------
Now is the time, for all good men to come.
is the time, for all good men to come.
the time, for all good men to come.
time, for all good men to come.
for all good men to come.
all good men to come.
good men to come.
men to come.
to come.
come.
cspice_nextwd is used primarily for parsing input commands consisting
of one or more words, where a word is defined to be any sequence
of consecutive non-blank characters. Successive calls to cspice_nextwd,
each using the previous value of `rest' as the input string, allow
the calling routine to neatly parse and process one word at a
time.
cspice_nextwd cuts the input string into two pieces, and returns them
separately. The first piece is the first word in the string.
(Leading blanks are ignored. The first word, which is returned in
the output argument `next', runs from the first non-blank character
in the string up to the first blank that follows it.) The second
piece is whatever is left after the first word is removed. The
second piece is left justified, to simplify later calls to cspice_nextwd.
1) If the input argument `string' is undefined, an error is
signaled by the IDL error handling system.
2) If the input argument `string' is not of the expected type, or
it does not have the expected dimensions and size, an error is
signaled by the Icy interface.
3) If any of the output arguments, `next' or `rest', is not a
named variable, an error is signaled by the Icy interface.
None.
None.
ICY.REQ
None.
J. Diaz del Rio (ODC Space)
-Icy Version 1.0.0, 07-JUN-2021 (JDR)
next word in a character_string
|