Table of contents
CSPICE_EQSTR determines whether two strings are equivalent.
Given:
a,
b arbitrary character strings.
help, a
STRING = Scalar
help, b
STRING = Scalar
the call:
eqstr = cspice_eqstr( a, b )
returns:
eqstr True if `a' and `b' are equivalent: that is, if `a' and `b'
contain the same characters in the same order, when blanks are
ignored and uppercase and lowercase characters are considered
equal.
help, eqstr
BOOLEAN = Scalar
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) This code provides examples of equivalent and non-equivalent
strings according to the algorithm implemented in cspice_eqstr.
Example code begins here.
PRO eqstr_ex1
;;
;; Local parameters.
;;
SETSIZ = 9L
;;
;; Initialize the two arrays of strings.
;;
str1 = [ 'A short string ', 'Embedded blanks', $
'Embedded blanks', ' ', $
'One word left out', 'Extra [] delimiters', $
'Testing 1, 2, 3', 'Case insensitive', $
'Steve' ]
str2 = [ 'ashortstring', 'Em be dd ed bl an ks', $
' Embeddedblanks', ' ', $
'WORD LEFT OUT', 'extradelimiters', $
'TESTING123', 'Case Insensitive', $
' S t E v E ' ]
;;
;; Compare the two arrays.
;;
for i=0L, SETSIZ-1L do begin
print
print, 'STR1 : ', str1[i]
print, 'STR2 : ', str2[i]
if ( cspice_eqstr( str1[i], str2[i] ) ) then begin
print, 'cspice_eqstr: equivalent.'
endif else begin
print, 'cspice_eqstr: NOT equivalent.'
endelse
endfor
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
STR1 : A short string
STR2 : ashortstring
cspice_eqstr: equivalent.
STR1 : Embedded blanks
STR2 : Em be dd ed bl an ks
cspice_eqstr: equivalent.
STR1 : Embedded blanks
STR2 : Embeddedblanks
cspice_eqstr: equivalent.
STR1 :
STR2 :
cspice_eqstr: equivalent.
STR1 : One word left out
STR2 : WORD LEFT OUT
cspice_eqstr: NOT equivalent.
STR1 : Extra [] delimiters
STR2 : extradelimiters
cspice_eqstr: NOT equivalent.
STR1 : Testing 1, 2, 3
STR2 : TESTING123
cspice_eqstr: NOT equivalent.
STR1 : Case insensitive
STR2 : Case Insensitive
cspice_eqstr: equivalent.
STR1 : Steve
STR2 : S t E v E
cspice_eqstr: equivalent.
This routine is provided for those cases in which two strings
must be compared, and in which allowances are to be made for
extra (leading, trailing, and embedded) blanks and differences
in case. For the most part,
cspice_eqstr ( a, b )
is True whenever
cspice_cmprss, ' ', 0L, a, tempa
cspice_ucase, tempa, tempa
cspice_cmprss, ' ', 0L, b, tempb
cspice_ucase, tempb, tempb
eqvlnt = tempa eq TEMPB
is True. There are two important differences, however.
1) The single reference to cspice_eqstr is much simpler to
write, and simpler to understand.
2) The reference to cspice_eqstr does not require any temporary
storage, nor does it require that the strings `a' and `b'
be changed. This feature is especially useful when
comparing strings received as subprogram arguments
against strings stored internally within the subprogram.
1) If any of the input arguments, `a' or `b', is undefined, an
error is signaled by the IDL error handling system.
2) If any of the input arguments, `a' or `b', is not of the
expected type, or it does not have the expected dimensions and
size, an error is signaled by the Icy interface.
None.
None.
ICY.REQ
None.
J. Diaz del Rio (ODC Space)
E.D. Wright (JPL)
-Icy Version 1.0.2, 10-AUG-2021 (JDR)
Edited the header to comply with NAIF standard. Added complete
code example.
Corrected -Abstract and -I/O sections that indicated that this
API would check for equality instead of equivalency. Removed
reference to IDL native code, as there is no IDL function that
performs the same checks as this API.
Added -Parameters, -Exceptions, -Files, -Restrictions,
-Literature_References and -Author_and_Institution sections, and
completed -Particulars section.
Removed reference to the routine's corresponding CSPICE header from
-Abstract section.
Added arguments' type and size information in the -I/O section.
-Icy Version 1.0.1, 19-FEB-2008 (EDW)
Corrected typo in "No match"" example; replaced "not" with
the logical negation operator "~".
-Icy Version 1.0.0, 16-JUN-2003 (EDW)
equivalent strings
|