Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing spaces form a Message

Status
Not open for further replies.

anirbanc

Programmer
Dec 22, 2008
2
IN
I have a i/p message line,consisting of some writing,some nos.etc. Now, anywhere in the msg there can be more than one space. I want to remove the spaces to one space if the
spaces are not at starting,or if its at staring then I
dont need any space.
for eg.
'a/c balace is $200.00 name is smith' sholud be
''a/c balace is $200.00 name is smith'

and if
' 'a/c balace is $200.00',I need it to be
'a/c balace is $200.00'

Please suggest me a way out.




 
Perhaps you could document what you mean by "horrible.".

I did in the next sentence. All table access in any COBOL I've touched is horrible compared to most other languages. This counts the list that you mentioned, which is the standard dogma that works for COBOL. COBOL (both mainframe and PC) just doesn't handle tables well.

Let me relate to you another example of mine, which has nothing to do with STRING, UNSTRING and INSPECT, but still has something to do with table access. I got to playing around in some downtime when I was working with coding different sorts in COBOL and testing their execution time on the mainframe (IBM COBOL for this and that, etc).

I found something curious, though. The sorts that, by traditional wisdom are the fastest (like quicksort), were actually quite slow within COBOL. I found this quite interesting, so I tested the algorithms further by counting different operations, and discovered something. The fastest algorithm, Combsort (3X faster in fact!), is the one that touches the table the least. And yes I was using indexes on all things. And yes, PC COBOL is just as consistent - you would think they would try to use the same algorithmic techniques that are used in the PC compilers where quicksort actually is the fastest.

Your code fails if the input string contains an "*", or whatever other character you might use for a marker.

Any byte can be used there without a problem, even non-printable characters which would never appear in a standard text string. Not a problem with what was posted.

Both of these statements have very high overhead, much more than referance modification could have.

Are you judging by what you think is happening by reading the source, or actually learning what's happening behind the scenes? Have you tested these things to see? Behind the scenes, STRING UNSTRING and INSPECT do things much more efficiently in most cases than what can be done in COBOL.

Like I mentioned, this thread involves much simpler things than the case I found where going to those things in a program reduced the execution time by half. But I did test what was posted in this thread (as copied, no modifications) before I made my assertion on a copy of Fujitsu COBOL 3.0, by throwing a large number of text strings at them. Want to take a guess which one was faster? Hint: It wasn't what TLeaders posted.

Measurement is not management.
 
By "other languages" do you mean anything like Visual Basic? At one job, my boss asked me to see what I could do with a VB program that was taking half the day to run. I wrote a COBOL program (Micro Focus V3.5) which ran literally in the blink of an eye (it was done before one's finger could be lifted off the Enter key). Perhaps a C program would be faster. But then we didn't have a C compiler.

BTW, many languages don't manipulate the strings in a table, they manipulate the string pointers. In the past, I have written a COBOL program to do it that way, it was much faster.
 
Well Glenn, you got me. I ran tests with RM/COBOL V11.01 and Micro Focus COBOL V 3.2.46 (very old) I ran three loops, each 90,000 times 1) your code 2) referance modification and 3) an empty loop.

MF COBOL 19.67 sec, 33.28 sec, .11 sec
RM/COBOL 1.33 sec, 5.26 sec, .02 sec

So there's someting going on behind the scenes.

I left the mainframe world very shortly after STRING, UNSTRING, and referance modification were introduced, so I never had an oportunity to see how they were implemented there. Referance modification should have been implemented at a very low level, the addresssing schemae for IBM mainframes has included referance modification as an integral part since the 60s.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top