source: trunk/SRC/ToBeReviewed/STRING/strtok.pro @ 226

Last change on this file since 226 was 226, checked in by pinsard, 17 years ago

corrections of some misspellings in some *.pro

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
RevLine 
[2]1;
2;+
[142]3;
4; @file_comments
5; Retrieve portion of string up to token.
[226]6;
[142]7; @categories
[157]8; String
[142]9;
10; @param STRING {in}{required}
[186]11; String to be split. Contains text after in, out token on output.
[226]12;
[142]13; @param TOKEN {in}{required}
[226]14; Token to use in splitting old.
[142]15;
[226]16; @keyword TRIM
[186]17; set to remove leading blanks from old before returning.
[142]18;
19; @keyword HELP
20; print useful message and exit.
[226]21;
[142]22; @returns
23; new   -- portion of string up to token.              out
24; old   -- portion of old after token.                 out, in
25;
26; @restrictions
27; Input parameter old is modified.
28; Token may be one or more characters.
[163]29; if token is not found, returns old and sets old to ''.
[226]30;
[142]31; @examples
[2]32;       If old is 'foo44 bar', then strtok( old, '44' ) would return
33;       'foo', and upon return, old will be left with ' bar'.  If /TRIM
34;       were set, old would be 'bar' on return.
35;
36;       If old='xyz', then new=strtok(old,'a') would return with
37;       new='xyz' and old=''.
[142]38;
39; @history
[7]40;       $Log: strtok.pro,v $
[2]41;       Revision 1.3  1996/06/14 20:00:27  mcraig
42;       Updated Copyright info.
43;
44;       Revision 1.2  1996/05/09 00:22:17  mcraig
45;       Added built in help.
46;
47;       Revision 1.1  1996/01/31 18:47:37  mcraig
48;       Initial revision
49;
[142]50; Thanks:
51;       To D. Linder who wrote GETTOK, part of the goddard library,
52;       upon which this is based.
53;
54; Release:
[7]55;       $Name: Rel_1_2 $
[2]56;
[142]57; Copyright:
[2]58;  Copyright (C) 1996 The Regents of the University of California, All
59;  Rights Reserved.  Written by Matthew W. Craig.
[226]60;  See the file COPYRIGHT for restrictions on distributing this code.
[2]61;  This code comes with absolutely NO warranty; see DISCLAIMER for details.
[142]62;
63; @version
64; $Id$
65;
[2]66;-
[163]67FUNCTION strtok, string, token, $
[2]68                 TRIM=trim, HELP=Help
[114]69;
70  compile_opt idl2, strictarrsubs
71;
[2]72
73; Back to the caller if error occurs.
74    On_error, 2
75
[226]76    IF (n_params() NE 2) OR keyword_set(Help) THEN BEGIN
[2]77        offset = '   '
78        print, offset+'Retrieve portion of string up to token.'
79        print, offset+'new = strtok( old, token )'
80        print, offset+'Inputs:'
81        print, offset+offset+'old   -- String to be split.  Contains text after    in, out'
82        print, offset+offset+'         token on output.'
83        print, offset+offset+'token -- Token to use in splitting old.              in'
84        print, offset+'Keywords:'
85        print, offset+offset+'/TRIM -- set to remove leading blanks from old '
86        print, offset+offset+'         before returning.'
87        print, offset+offset+'/HELP -- print useful message and exit.'
88        print, offset+'Outputs:'
89        print, offset+offset+'new   -- portion of string up to token.              out'
90        print, offset+offset+'old   -- portion of old after token.                 out, in'
91        print, offset+'Side effects:'
92        print, offset+offset+'Input parameter old is modified.'
93        print, offset+'Notes:'
94        print, offset+offset+'Token may be one or more characters.'
95        print, offset+offset+"If token is not found, returns old and sets old to ''."
96        print, offset+'Examples:'
97        print, offset+offset+"If old is 'foo44 bar', then strtok( old, '44' ) would return'"
98        print, offset+offset+"  'foo', and upon return, old will be left with ' bar'.  If /TRIM"
99        print, offset+offset+"  were set, old would be 'bar' on return."
100;'
101        print, offset+offset+"If old='xyz', then new=strtok(old,'a') would return with"
102        print, offset+offset+"  new='xyz' and old=''."
103        return, -1
[226]104    ENDIF
[2]105
106    pos = strpos(string, token)
107
108    IF (pos GE 0) THEN BEGIN
[226]109        front = strmid(string, 0, pos)
[2]110        string = strmid(string, pos + strlen(token), strlen(string))
111        IF keyword_set(trim) THEN string = strtrim(string, 1)
112        return, front
113    ENDIF
[226]114
[2]115    front = string
116    string = ''
117    return, front
[226]118
[2]119END
120
Note: See TracBrowser for help on using the repository browser.