MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Stepping through a string charcter by character

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF
View previous topic :: View next topic  
Author Message
John Corbin
Beginner


Joined: 23 Jan 2004
Posts: 38
Topics: 21

PostPosted: Wed Feb 04, 2004 1:43 pm    Post subject: Stepping through a string charcter by character Reply with quote

Hi...

In REXX I need to test each character in a string and do some action based on the outcome of the test.

in english it would like this:

WHILE not end of string DO
IF string[I] = 'A'
perform some action
ELSE IF string[I] = 'B'
perform sone action
ELSE IF string[I] = 'C'
etc etc....

I=I+1
ENDWHILE

I am aware of the REXX functiosn INDEX and POS but I do not see how I can make these work they way I want.

Any thoughts ?
Back to top
View user's profile Send private message
ofer71
Intermediate


Joined: 12 Feb 2003
Posts: 358
Topics: 4
Location: Israel

PostPosted: Wed Feb 04, 2004 2:47 pm    Post subject: Reply with quote

Try this
Code:
/* REXX */

STR = 'TEST'

DO I = 1 TO LENGTH(STR)
  CHAR = SUBSTR(STR,I,1)
  SELECT
    WHEN CHAR = 'A' THEN
     do something
    WHEN CHAR = 'B' THEN
     do something else
    OTHERWISE
      NOP
  END
END

EXIT


O.
________
California Medical Marijuana Dispensary


Last edited by ofer71 on Thu Mar 17, 2011 10:37 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Manas Biswal
Intermediate


Joined: 29 Nov 2002
Posts: 382
Topics: 27
Location: Chennai, India

PostPosted: Thu Feb 05, 2004 11:09 am    Post subject: Reply with quote

Basically reinventing the wheel by Ofer71 but just to try another function, you can also try this -

Code:

/***** rexx ******/
var1 = 'manas'
restvar = var1
do i = 1 to length(var1)
   parse var restvar var2 2 restvar
   /* Do whatever you want to do with var2 here */
end
exit


Regards,
Manas
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Maton_Man
Beginner


Joined: 30 Jan 2004
Posts: 123
Topics: 0

PostPosted: Mon Feb 09, 2004 6:02 pm    Post subject: Reply with quote

A sneakier way to do it without a massive SELECT statement would be:

var = "ACBDE"

do i = 1 to length(var)
interpret("call "left(var,1))
end

a:
whatever you do when you get 'A'
return

b:

return
whatever you do when you get 'B'
etc...
_________________
My opinions are exactly that.
Back to top
View user's profile Send private message
Maton_Man
Beginner


Joined: 30 Jan 2004
Posts: 123
Topics: 0

PostPosted: Mon Feb 09, 2004 6:05 pm    Post subject: Reply with quote

*argh!!!!*

Replace left(var,1) with substr(var,i,1) - got distracted...
_________________
My opinions are exactly that.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group