View previous topic :: View next topic
|
Author |
Message |
vasan_4u
New User
Joined: 28 Jun 2005 Posts: 35 Location: chennai
|
|
|
|
I have a string like this
STR='&HLQ..&SYS..&JOBNAME..LSCBSA05.SELRPT'
Now i need to replace the &HLQ/&SYS/&JOBNAME to someother value is that possible ?
I cant use PARSE command for the same. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
What have you tried and what were the results that have prompted you to ask on the forum ? |
|
Back to top |
|
|
vasan_4u
New User
Joined: 28 Jun 2005 Posts: 35 Location: chennai
|
|
|
|
I dint try any thing as i dont know how to do a replace.
But i should not be doing it with the PARSE comand.
Can you help me in this. |
|
Back to top |
|
|
Douglas Wilder
Active User
Joined: 28 Nov 2006 Posts: 305 Location: Deerfield IL
|
|
|
|
Yes, it is possible.
1) Which language do you want to do this in, Clist or REXX?
2) Is the string into which you want to replace the variables a constant? Can this be hardcoded into the program?
3) Are the names of the variables to be replaced constant? Can these be hard coded in the program?
4) Could the variables occur more than 1 time in the string?
5) Where are you getting this string?
6) Where are you getting the contents of the variables to put into the string?
7) Have you already coded the program to get the needed strings?
If you are doing this in REXX have you looked at the POS and SUBSTR built-in functions?
If you are doing this in Clist have you looked at symbol substitution?
We try to be helpful but there is a lot about what you are doing that we do not know. |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
Almost seems like a good candidate for an easy EDIT routine. |
|
Back to top |
|
|
vasan_4u
New User
Joined: 28 Jun 2005 Posts: 35 Location: chennai
|
|
|
|
->I am doing it in REXX.
->Those value cannot be hardcoded and its not constant.
For example the value of &HLQ will be LS. which is stored in a aray.
I have coded the program and I have this string alone in a variable. |
|
Back to top |
|
|
Douglas Wilder
Active User
Joined: 28 Nov 2006 Posts: 305 Location: Deerfield IL
|
|
|
|
It would be helpful to see the code you have already developed.
How do you know which element in the array is substituted for each variable?
It appears that you may need to loop using the POS function to find the next "&" then use the POS function to find the next "." use the SUBSTR to find the name of the variable, then use the SUBSTR to put the value in place of the variable name.
It might be easier to do as Kevin suggested, write the string to a dataset, edit it, and do change all commands to replace the variables. |
|
Back to top |
|
|
Douglas Wilder
Active User
Joined: 28 Nov 2006 Posts: 305 Location: Deerfield IL
|
|
|
|
I though I had something like this around somewhere. I found it and modified it to fit your case. I do not know how you will incorporate this into your existing code, but here it is.
Code: |
/* REXX */
TRACE ALL
VAR = 'HLQ'
HLQ = 'ABC'
SYS = 'DEFGH'
JOBNAME = 'IJKLMN'
/* STRNG = HLQ||'.'||SYS||'.'||JOBNAME||'.LSCBSA05.SELRPT' */
/* SAY STRNG */
STRNG = '&HLQ..&SYS..&JOBNAME..LSCBSA05.SELRPT'
SAY STRNG
STRT = POS('&',STRNG)
DO WHILE STRT > 0
ENND = POS('.',STRNG,STRT)
VAR = SUBSTR(STRNG,STRT+1,ENND-STRT-1)
STRNG = LEFT(STRNG,STRT-1)||VALUE(VAR)||SUBSTR(STRNG,ENND+1)
SAY STRNG
STRT = POS('&',STRNG)
END
SAY ' '
SAY STRNG
SAY ' '
|
|
|
Back to top |
|
|
|