View previous topic :: View next topic
|
Author |
Message |
Priyesh Tewari
New User
Joined: 24 Jun 2008 Posts: 7 Location: Pune
|
|
|
|
Hi,
Can some bdy tell me an answer to this. I have a string 'X Y Z A'. There are spaces in between al the alphabets. Now I want to remove all the spaces and just have the output string as XYZA. How can I do it? Please help...
Thanks
Priyesh |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Is the variable DBCS? UTF-8?
Assuming it is a "normal" (i.e., not DBCS nor UTF) variable, reference modification will do this -- see the COBOL Language Reference manual (link at the top of the page) for details on how to code it. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Code: |
01 input-string-size pic s9(4) comp.
01 input-string pic x(10). (or however large it is)
01 input-table
redefines
input string.
05 input-item pic x(01)
occurs 10 times (or however large input-string is)
indexed by input-index.
88 input-is-space value space.
*
01 output-string pic x(10). (or however large input-string is)
88 output-string-to-space value spaces.
01 output-table
redefines
output string.
05 output-item pic x(01)
occurs 10 times (or however large input-string is)
indexed by output-index.
*
|
Code: |
move length of input-string to input-string-size.
set output-index to 1
set output-string-to-space true
perform varying input-index
from 1
by 1
until input-index > input-string-size
if input-is-space(input-index)
then
continue
else
move input-item (input-index)
to output-item (output-index)
set output-index
up by 1
end-if
end-perform
|
I would think, IMUO that advice to a novice should be to use/learn indexing first, since it is much more effecient than reference modification, especially since he could not figure out how to accomplish this task. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Robert Sample wrote: |
Assuming it is a "normal" |
, you're now habitual of this forum, Robert. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
but it' s much more fun with ... ABnormal <thingies>
as in Frankestein junior |
|
Back to top |
|
|
|