Reading blanks in a string, replace them with zeros.



IBM's Command List programming language & Restructured Extended Executor

Reading blanks in a string, replace them with zeros.

Postby dbordon » Wed Mar 06, 2013 4:13 am

Hi all
Tried to get my answer in the forum but i could not.
My question is simple, i read a PDS dataset, using SUBSTR i delete the part of a string i'm not interested in and the remaining data, wich is 4 integer bytes are written with spaces and i wanted to trasnform those blanks with zeros.

Example:
I read the following line:
xxxxx xxxxxx(1234)
do the subtream and get
1234

but... If a read xxxxx xxxxx ll xxx ( 34)
the result is
34
and i need the result as
0034

I hope to be clear in my explanation, if you need i can write the peace of program i'm using. Tried with the funtion RIGTH, with 4 bytes and filling with zeros, but does not worked.

Thanks !
dbordon
 
Posts: 2
Joined: Tue Jan 24, 2012 8:56 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Reading blanks in a string, replace them with zeros.

Postby NicC » Wed Mar 06, 2013 9:16 am

How did it not work? I find RIGHT and LEFT a bit "about-face" if I do not check the syntax first in the manual. Did you try LEFT just in case? And it is SUBSTRing not SUBSTReam!
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Reading blanks in a string, replace them with zeros.

Postby Pedro » Wed Mar 06, 2013 7:23 pm

Try using the TRANSLATE function.
Pedro Vera
User avatar
Pedro
 
Posts: 686
Joined: Thu Jul 31, 2008 9:59 pm
Location: Silicon Valley
Has thanked: 0 time
Been thanked: 53 times

Re: Reading blanks in a string, replace them with zeros.

Postby enrico-sorichetti » Wed Mar 06, 2013 7:34 pm

str.1 = "xxxxx xxxxx(1)"
str.2 = "qwqwqw(1) zqzqzq"
str.3 = "xxxxx xxxxx(333333)"
str.4 = "(1)ryryyrryyy"

do  s = 1 to 4
    parse var str.s head "(" tokn ")" tail
    say right(s,   2) "head" ">"head"<"
    if length(tokn) <= 8 then ,
        say right(" ", 2) "tokn" left(">"tokn"<",10) ">>"right(tokn,4,"0")"<<"
    else ,
        say right(" ", 2) "tokn" ">"tokn"<" ">>"right(tokn,4,"0")"<<"
    say right(" ", 2) "tail" ">"tail"<"
end

exit
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3006
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 165 times

Re: Reading blanks in a string, replace them with zeros.

Postby Pedro » Sat Mar 09, 2013 3:16 am

Enrico, it is not clear what you are demonstrating with your example. I think it should process this string:
 str.5 = "xxxxx xxxxx(  34)"     

which is what the poster was asking about. The ' 34' needs to be TRANSLATEd to '0034'
Pedro Vera
User avatar
Pedro
 
Posts: 686
Joined: Thu Jul 31, 2008 9:59 pm
Location: Silicon Valley
Has thanked: 0 time
Been thanked: 53 times

Re: Reading blanks in a string, replace them with zeros.

Postby enrico-sorichetti » Sat Mar 09, 2013 7:39 pm

just change

right(tokn,4,"0")
 to
right(strip(tokn),4,"0")

and You will have the result the TS needed

You should also have noticed that in my replies I rarely stick only/simply to the lowly technicalities
but I try to show also the general approach on tackle the problems being discussed

in this case how to parse a parentheses enclosed token

and the way the TS posted the data it was not clear how many blanks had to be handled
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3006
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 165 times


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post