View previous topic :: View next topic
|
Author |
Message |
Pragati Soni
New User
Joined: 18 Jan 2008 Posts: 47 Location: India
|
|
|
|
I need to count number of '.' in a string like 'PRD.Y00205.REXX.QHTOOL.XXX.YYY'.
Actually I need to check if the first letter of every substring is an alphabet and neither number nor spaces. For this I need to seperate PRD, Y00205, REXX, QHTOOL, XXX, YYY.
Approach1:
I can PARSE the string, but the issue is the number of substrings are not known before hand.
I mean it can be
'PRD.Y00205.REXX.QHTOOL.XXX.YYY'
or
'PRD.Y00205.REXX.QHTOOL.XXX'
or
'PRD.Y00205.REXX.QHTOOL'
or
so on
So I am thinking to count the number of '.' and then the number of substrings can be +1. and I can easily parse the string.
Approach2:
I also tried to use translate func to replace '.' by spaces but it is not working for spaces.
QHTLLOCS = TRANSLATE('PRD.Y00205.REXX.QHTOOL.XXX.YYY','.',' ')
I thought of replacing the '.' by spaces and then counting the words delimited by space.
Please suggest something especially for Approach1.
Thanks in advance. |
|
Back to top |
|
|
acs_amit
New User
Joined: 30 Apr 2009 Posts: 14 Location: Noida
|
|
|
|
Why don't you try to check first character like this.. I hope this works
Code: |
ABC = 'PRD.Y00205.REXX.QHTOOL.XXX.YYY'
CHARAC = SUBSTR(ABC,1,1)
SAY CHARAC
IF ((CHARAC = ' ') | (TRANSLATE(DATATYPE(CHARAC)) = 'NUM'))
THEN
SAY 'FIRST CHARACTER IS NEITHER SPACES NOR NUMERIC'
ELSE
SAY 'FIRST CHARACTER MAY BE CHAR' |
This is extracting first character of your input string and checking that it shouldn't be spaces or Numeric..
Translate function is used to make the input string in CAPS.
let me know if this helps |
|
Back to top |
|
|
Mickeydusaor
Active User
Joined: 24 May 2006 Posts: 258 Location: Salem, Oregon
|
|
|
|
change your translate to this, switch the space and period around
QHTLLOCS = TRANSLATE('PRD.Y00205.REXX.QHTOOL.XXX.YYY',' ','.')
count = words(qhtllocs) |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Code: |
rest_of_it = input_string
node_stem.0 = 0
Do i = 1 to 10
parse var rest_of_it node_stem.i '.' rest_of_it
if rest_of_it = '' then leave
node_stem.0 = i
end
|
edited to correct some code. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
actually, ignore my previous post.
Code: |
rest_of_it = input_string||'.' <<<<<change here
node_stem.0 = 0
Do i = 1 to 10
parse var rest_of_it node_stem.i '.' rest_of_it
node_stem.0 = i <<<<reversed
if rest_of_it = '' then leave <<<<<<these lines
end
|
|
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2547 Location: Silicon Valley
|
|
|
|
Yes, it is unlikely, but there could be more than 10 levels.
I prefer Mickey's translate and word approach. It seems cleaner to me. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
standard approach to parse a dataset name
Code: |
dsn = "AAA.DEEE.E33.R55.T66"
do i = 1 while dsn <> ""
parse var dsn hlq "." dsn
hlq.i = hlq
hlq.0 = i
end
do i = 1 to hlq.0
say right(i,2) hlq.i
end
|
edited to add a comment
Hi Dick!
sometimes the fingers are faster than the eyes
I had not seen that You had already posted the same solution
I just cut and pasted the code from my snippet collection! |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2547 Location: Silicon Valley
|
|
|
|
Another approach:
Code: |
dsn = "AAA.DEEE.E33.R55.T66"
qualifiers = TRANSLATE(dsn,' ','.')
do i = 1 to words(qualifiers)
say right(i,2) word(qualifiers, i)
end |
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Enrico,
your solution is much better code than mine. As Pedro pointed out,
I limited myself to 10 nodes.
though the TRANSLATE function is slick, using WORD to separate the parts
inhibits the proofing that the TS required:
Quote: |
Actually I need to check if the first letter of every substring is an alphabet and neither number nor spaces. For this I need to seperate PRD, Y00205, REXX, QHTOOL, XXX, YYY. |
|
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2547 Location: Silicon Valley
|
|
|
|
The actual proofing has not been discussed yet. It would be something like this:
Code: |
/* rexx */
dsn = "AAA.!EEE.E33.R55.T66"
qualifiers = TRANSLATE(dsn,' ','.')
validC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
do i = 1 to words(qualifiers)
say right(i,2) word(qualifiers, i)
If TRANSLATE(left(word(qualifiers, i),1) ,' ', validC) ¬= ' ' Then
Say 'wrong qualifier'
end |
|
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2547 Location: Silicon Valley
|
|
|
|
Quote: |
It would be something like this: |
It would be something like that, but NOT exactly that. As DBZ mentioned, there might be some other error conditions to look for.
And now I hesitate to give entire solutions for fear that some of the forumers will not learn to do on their own. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Ah yes, you must be referring to the popular saying, "Give a man a fish and he'll eat for a day; teach a man to fish and he'll buy a bass boat, go out to the lake, and drink beer all day." |
|
Back to top |
|
|
MBabu
Active User
Joined: 03 Aug 2008 Posts: 400 Location: Mumbai
|
|
|
|
here is the dumbest answer you will see today but good for a laugh I guess.
Code: |
/* REXX - assumes running in TSO, English */
parse upper arg dsn .
call msg 'OFF'
if pos('INVALID DATASET NAME',sysdsn("'" || dsn || "'"))>0 then
say dsn 'is not a valid data set name'
|
|
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
follow on to check for alpha only
Code: |
dsn = "AAA.DEEE.E33.R55.T66"
do i = 1 while dsn <> ""
parse var dsn hlq "." dsn
hlq.i = hlq
hlq.0 = i
end
do i = 1 to hlq.0
say right(i,2) hlq.i
end
do i = 1 to hlq.0
if datatype(left(hlq.i,1)) <> "M" then ,
say "invalid qualifier" right(i,2) hlq.i
end
|
re edited to fix sloppy testing ...
use as Dick suggested
Code: |
do i = 1 to hlq.0
if datatype(left(hlq.i,1),"M") <> 1 then ,
say "invalid qualifier" right(i,2) hlq.i
end
|
|
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Pragati Soni wrote: |
I need to count number of '.' in a string like 'PRD.Y00205.REXX.QHTOOL.XXX.YYY'.
Actually I need to check if the first letter of every substring is an alphabet and neither number nor spaces. |
If you need to validate a dataset name, there are other ways too:
* If you receive this value from a panel, you can use the VER(...,DSNAME) command,
* You can use SYSDSN to check both validity of name and existence of file.
ISPF uses the following rules for its dataset name validation:
Quote: |
A data set name qualifier must begin with an alphabetic character (A-Z, $, @, or #). The remaining characters must be either uppercase alphanumeric or a hyphen (-). A period is used to connect each qualifier in the data set name.
ISPF first determines if the TSO/E NOPREFIX PROFILE option is in use. If it is, ISPF does use a prefix in the calculation of the data set length. A maximum of 44 characters can be entered for a data set name, if that data set name is enclosed in quotes. If the TSO/E NOPREFIX PROFILE option is in use, a maximum of 44 characters can be entered for a data set name when it is not enclosed within quotes. If the TSO/E NOPREFIX PROFILE option is not in use, a maximum of 42 characters can be entered for a data set name, not enclosed in quotes. ISPF uses the minimum data set prefix of two characters (one character and a period separator) during its calculation of the data set name length. |
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
spent so much time insuring the bit & bytes were ok.......
ah, the forest for the trees.
thx Marso for injecting a little 'right tool for the job' thinking. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Sometimes I wish I could inject also some 'right question for the job' thinking... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Sometimes we get lucky and can do so. . . |
|
Back to top |
|
|
|