View previous topic :: View next topic
|
Author |
Message |
monasu1998
Active User
Joined: 23 Dec 2005 Posts: 176 Location: India
|
|
|
|
Hi,
I am facing a strange situation where the EXAMINE replace is not working for me.
Situation:
I have a work file. I want to read the records and in each record I want to replace the '"' (Double quote) with SPACE and then write the record to an output file.
I coded as
EXAMINE #STRING FOR '"' REPLACE WITH ' '
When I see the output file, I do not find the '"' s replaced with SPACE.
Is there any specific reason for this.
The same statement is working for single quote, or any other symbol.
Little urgent please.
Thanks,
Aswini |
|
Back to top |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
Try EXAMINE FULL #STRING FOR FULL '"' REPLACE WITH FULL ' '.
O. |
|
Back to top |
|
|
monasu1998
Active User
Joined: 23 Dec 2005 Posts: 176 Location: India
|
|
|
|
Thought I hve already tried with
EXAMINE FULL...........
let me try with other 2 FULLs in the same statement and see.
Thanks, |
|
Back to top |
|
|
Ralph Zbrog
New User
Joined: 21 Nov 2009 Posts: 58 Location: California
|
|
|
|
By default, Natural will translate double-quotes to single-quotes at compile time, presuming that you will be using double-quotes within literal strings to represent apostrophes. For example, to write the name O'Brien, you could code
which I find easier than
This action is controlled by the TQ and TQMARK parameters. To set it programmatically, code an OPTIONS statement.
Code: |
DEFINE DATA LOCAL
1 #A (A1) INIT <'"'> /* Translates to apostrophe
END-DEFINE
WRITE #A #A (EM=H)
OPTIONS TQMARK=OFF /* Do not translate
#A := '"'
WRITE #A #A (EM=H)
END |
The output will look like this:
The other solution is to specify the double-quote as a hexadecimal value.
Code: |
DEFINE DATA LOCAL
1 #STRING (A40)
1 #DQ (A1) INIT <H'7F'> /* Double-quote
END-DEFINE
READ WORK 1 #STRING
WRITE 'Before:' #STRING
EXAMINE #STRING FOR #DQ REPLACE WITH ' '
WRITE ' After:' #STRING
END-WORK
END |
Quote: |
Page 1
Before: O"Brien, O"Houlihan, and O"Shaughnessy
After: O Brien, O Houlihan, and O Shaughnessy |
|
|
Back to top |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
Please note that the OPTIONS statement is only available with Natural Optimizer Compiler.
O. |
|
Back to top |
|
|
Ralph Zbrog
New User
Joined: 21 Nov 2009 Posts: 58 Location: California
|
|
|
|
Would you check that please, Ofer71?
I created my example with Natural for Windows, which has no optimizer, and verified it on a machine that has NOC installed, but the documentation states that OPTIONS can be used for regular compiler options (as in COMPOPT) and Optimizer Compiler options (as in NOCOPT). |
|
Back to top |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
Just checked it in my z/OS (no NOC) - not allowed.
O. |
|
Back to top |
|
|
Steve Robinson
New User
Joined: 14 Nov 2009 Posts: 12 Location: U.S.
|
|
|
|
A note about the word FULL in the EXAMINE statement.
Basically, FULL means trailing blanks count. One should not scatter FULLs through an EXAMINE "hoping" for a good result.
Consider:
1 #A (A10) INIT <'AB C'>
EXAMINE #A FOR ' ' GIVING NUMBER #N /* #N is 1
EXAMINE FULL #A FOR ' ' GIVING NUMBER #N /* #N is 7
---------------------
1 #A (A30) INIT <'LOOKING FOR WORDS THAT END IN R'>
1) EXAMINE #A FOR 'R ' GIVING NUMBER #N /* #N is 3
2) EXAMINE #A FOR FULL 'R ' GIVING NUMBER #N /* #N is 1
3) EXAMINE FULL #A FOR FULL 'R ' GIVING NUMBER #N /* #N is 2
Explanations
1) without the word FULL before 'R ' this is looking for R's.
2) with the word FULL, this is looking for 'R '. HOWEVER, without the word FULL before #A, the final R (which does have a blank, actually, a bunch of them, after the R) does not count
3) with both FULLs, the final R counts
Understand what the statement does, then use the optional words/clauses to fit your needs.
-----------------
steve |
|
Back to top |
|
|
|