|
Scott, Usually, I follow what you are doing. However, the following has me scratching my head: > // > // Or, perhaps just dump all tokens to an array > // > > x = 0; > tokens(*) = gettok( blah : '|' : x ); How does this load the array? Doesn't gettok() only return one token? Thanks, Charles > -----Original Message----- > From: Scott Klement [mailto:rpg400-l@xxxxxxxxxxxxxxxx] > Sent: Wednesday, August 18, 2004 1:52 PM > To: RPG programming on the AS400 / iSeries > Subject: Re: strtok > > > > In fact, since it won't take any significant time, here... > I'll write one > for you: > > H DFTACTGRP(*NO) > > D gettok PR 1024A varying > D string 65535A varying const > options(*varsize) > D delims 50A varying const > D pos 10I 0 > > d blah s 100A varying > D tokens s 100A varying dim(50) > D x s 10I 0 > D y s 10I 0 > > D msg s 52A > > /free > > Blah = 'Test||||||123|x|||8900'; > x = 0; > y = 0; > > // > // Get each token from the string and DSPLY it > // > > dow ( x <= %len(blah) ); > y = y + 1; > msg = 'token ' + %char(y) + '=' > + gettok( blah : '|' : x ); > dsply msg; > enddo; > > // > // Or, perhaps just dump all tokens to an array > // > > x = 0; > tokens(*) = gettok( blah : '|' : x ); > > for y = 1 to %elem(tokens); > msg = 'elem ' + %char(y) + '=' + tokens(y); > dsply msg; > endfor; > > *inlr = *on; > > /end-free > > > > > *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > * gettok(): Get next token from string > * > * string = (input) string to search > * delims = (input) delimiters > * pos = (i/o) next position to search. At the start > * of a string, set this to zero. Pass > * it on subsequent calls to remember where > * you left off. > * > * Returns the token found. > *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > P gettok B > D gettok PI 1024A varying > D string 65535A varying const > options(*varsize) > D delims 50A varying const > D pos 10I 0 > > D res s 1024A varying > D start s 10I 0 > D c s 1A > > /free > > start = pos + 1; > %len(res) = 0; > > for pos = start to %len(string); > > c = %subst(string:pos:1); > > if %check(delims:c) = 1; > res = res + c; > else; > leave; > endif; > > endfor; > > return res; > > /end-free > P E
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.