View previous topic :: View next topic |
Author |
Message |
pradeepg Beginner

Joined: 06 Jan 2003 Posts: 25 Topics: 12 Location: Columbus, OH
|
Posted: Thu Aug 25, 2005 10:11 am Post subject: REXX equivalent of COBOL UNSTRING function |
|
|
Hello List,
Is there any function available in REXX to unstring the data-field into different variable like COBOL UNSTRING function.
My requirement is to unstring a dataset name into different variables to get the HLQ, MLQ. etc....
Ex: Dataset name is: ABC.XYX.DEF.IJK
I want them in 4 different variables delimited by . (dot).
HLQ should have ABC
MLQ should have XYZ etc.....
Thanks in advance.
- Pradeep |
|
Back to top |
|
 |
Manas Biswal Intermediate

Joined: 29 Nov 2002 Posts: 382 Topics: 27 Location: Chennai, India
|
|
Back to top |
|
 |
superk Advanced

Joined: 19 Dec 2002 Posts: 684 Topics: 5
|
Posted: Thu Aug 25, 2005 10:29 am Post subject: |
|
|
Wouldn't a PARSE command have worked?
dataset_name = 'ABC.XYX.DEF.IJK'
PARSE VAR dataset_name HLQ '.' MLQ '.' THIRDLQ '.' FOURTHLQ . |
|
Back to top |
|
 |
pradeepg Beginner

Joined: 06 Jan 2003 Posts: 25 Topics: 12 Location: Columbus, OH
|
Posted: Thu Aug 25, 2005 10:39 am Post subject: |
|
|
Thanks superk. You gave me very simple solution. Thats what I was looking for.
- Pradeep |
|
Back to top |
|
 |
semigeezer Supermod
Joined: 03 Jan 2003 Posts: 1014 Topics: 13 Location: Atlantis
|
Posted: Thu Aug 25, 2005 11:27 am Post subject: |
|
|
Parse is very powerful, and faster than most of the string builtins. If you learn to use it well, you will probably never need to use substr, although you run the risk of writing code that is slightly more difficlut for others to understand.
For example, you can initialize many variables at once:
Parse value 'one two' with v_one V_2 empty_1 empty_2
or you can do substringing
Parse vara leftFiveChars 6 restOfString
or swap variables (assuming no spaces)
Parse val1 val2 with val2 val1
You can even increment a stem variable index and assign the value to the new tail in one line:
parse value (line.0+1) 'new stuff' with 1 x line.x 1 line.0 .
(that last one looks silly, but it can be useful in practice)
Parse is the most misunderstood Rexx feature, but also one of the most powerful. |
|
Back to top |
|
 |
|
|