View previous topic :: View next topic
|
Author |
Message |
Johore
Specialist
Joined: 12 Sep 2003 Posts: 19
|
|
|
|
Hi team,
How do we Trim the Trailing blanks from a sentence using STRING function. Is there an easy way , using another function also ??
Quote: |
ex ... INPUT - PIC X(80) = "THE QUICK BROWN FOX. "
output - "THE QUICK BROWN FOX." |
Thanks,
johore |
|
Back to top |
|
|
Johore
Specialist
Joined: 12 Sep 2003 Posts: 19
|
|
|
|
Hi ..
One of the simplest way i could think of is using a STRING function
Code: |
SRTING INPUT DELIMITED BY " " ( two spaces)
INTO OUTPUT |
Is there any simpler way
Thanks, |
|
Back to top |
|
|
imvs
New User
Joined: 12 May 2004 Posts: 33
|
|
|
|
Johore
Couple of ways to trim the trailing spaces.
1. using instrinc function REVERSE
MOVE FUNCTION REVERSE(INPUT) TO INPUT-R.
INSPECT INPUT-R TALLYING CNTR FOR LEADING SPACES.
COMPUTE INP-LEN = LENGTH OF INPUT-R - CNTR.
INPUT-TRIM = MOVE INPUT(1:INP-LEN)
2.
MOVE LENGTH OF INPUT TO STR-LEN.
PERFORM VARYING SUB FROM STR-LEN BY -1
UNTIL INPUT(SUB:1) NOT = SPACE
END-PERFORM
MOVE INPUT(1:SUB) TO INPUT-TRIM. |
|
Back to top |
|
|
princess
New User
Joined: 14 Jan 2007 Posts: 1 Location: chennai
|
|
|
|
Hi,
I just want to know if how can I perform the validation of the trim string like this.
What should be done to compare the trim string into another variable.
example:
the trim string i got is OUTPUT-STR = 'fox'
and i want to compare if the OUTPUT-STR = 'fox' exist in TXT-FIELD.
If TXT-FIELD = 'The quick brown fox jumps over the lazy dog'
Please let me know the answer. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
There is a link to manuals at the top of the page. Click on it, find the COBOL Language Reference manual, and read up on the INSPECT statement. |
|
Back to top |
|
|
|