|
This will do what you need, in only one pass:
d string2test s 1024a inz('this_is_my_test_string')
d substring s 1024a inz
d i1 s 10i 0 inz
d i2 s 10i 0 inz
d i3 s 10i 0 inz
d counter s 10i 0 inz
/free
Reset i1;
Reset i2;
Reset i3;
For counter = %len(%trim(string2test)) downto 1;
If %subst(string2test:counter:1) = '_';
Select;
When i1 = *zeros;
i1 = counter;
When i2 = *zeros;
i2 = counter;
When i3 = *zeros;
i3 = counter;
Leave;
EndSl;
EndIf;
EndFor;
If i3 <> *zeros;
substring = %subst(string2test:
i3 + 1:
i2 - i3 - 1);
Else;
substring = *blanks;
EndIf;
/end-free
If there are at least 3 underscore characters in the string to test,
substring now contains the text between underscore 2-from-last and
3-from-last.
In this case, it will contain 'my'.
I hope this helps,
Peter Colpaert
Application Developer
PLI - IT - Kontich, Belgium
-----
Yoda of Borg are we. Futile is resistance, assimilated will you be.
-----
"Stiju Easo" <stiju.as400@xxxxxxxxx>
Sent by: rpg400-l-bounces@xxxxxxxxxxxx
05/04/2006 15:08
Please respond to
RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>
To
Michael_Schutte@xxxxxxxxxxxx, rpg400-l@xxxxxxxxxxxx
cc
Subject
Re: RPGLE pgm to parse a string
Sorry if i have trobuled u
thing is that i want to get 'my' from 'this_is_my_test_string'
where everything could be varible except the fact that varible i want to
extract comes b/w second from last and third from last '_',
i hope u clear with it, from my analisis what i found is
1) there r very few operators/built in functions which could help me
while
i come from right to left,
2) going from left to right i cant determine where the string comes( i
need
2 pass for that)
i think this results in more computation
thats why i asked for alternative
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.