About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: December 2006

URL: http://cxc.harvard.edu/ciao3.4/strchop.tm.html
Hardcopy (PDF): A4 | Letter
AHELP for CIAO 3.4 strchop Context: slangrtl

Synopsis

Chop or split a string into substrings.

Syntax

String_Type[] strchop (String_Type str, Integer_Type delim,
Integer_Type quote)

Description

The strchop function may be used to split-up a string str that consists of substrings delimited by the character specified by delim. If the integer quote is non-zero, it will be taken as a quote character for the delimiter. The function returns the substrings as an array.

Example

The following function illustrates how to sort a comma separated list of strings:

     define sort_string_list (a)
     {
        variable i, b, c;
        b = strchop (a, ',', 0);

        i = array_sort (b, &strcmp);
        b = b[i];   % rearrange

        % Convert array back into comma separated form
        return strjoin (b, ",");
     }

The semantics of this strchop and strchopr have been changed since version 1.2.x of the interpreter. Old versions of these functions returned the values on the stack, which meant that one could not chop up arbitrarily long strings that consist of many substrings.

The function strchopr should be used if it is desired to have the string chopped-up in the reverse order.

Hardcopy (PDF): A4 | Letter
Last modified: December 2006



The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory.
60 Garden Street, Cambridge, MA 02138 USA.    Email: cxcweb@head.cfa.harvard.edu
Smithsonian Institution, Copyright © 1998-2004. All rights reserved.