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

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

corrections of some headers and parameters and keywords case. change of pro2href to replace proidl

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