On 28/08/2008, at 2:20 AM, Doug Palme wrote:
Since the ' is the delimiter for a character field....is there
anyway for
me to test for it?
All these responses with 'might' and 'try' and other guesses. The
standard solution in RPG, COBOL, and CL to this problem of embedding
the enclosing character is simply to double it. That is if you want a
constant containing a single apostrophe you need to specify FOUR of
them. One is the start of the constant, one is the end of the
constant, one is the value itself and one is doubled so the compiler
does not interpret the previous one as an end marker. Thus:
D APOST C CONST('''')
Simple. In your case you want an apostrophe within a larger string so
the same principle applies: double it. Thus.
D @INV c CONST('!@#-c-&\}|NOT{?><.`~||(),*$+-%
D ;:"''ABCDEFGHIJKLMNOPQRSTUVWXYZ.')
Note the two apostrophes between the quote character and the capital
A character.
The same principle applies to any delimiter such as a quote character
or the C-language escape character \.
This behaviour is explained in the RPG Reference manual under
Literals (on page 121 for VRM510) if anyone except me actually
bothered reading it.
An apostrophe required as part of a literal is represented by two
apostrophes.
For example, the literal O’CLOCK is coded as ‘O’’CLOCK’.
Note that using a hexadecimal representation is cheating somewhat and
while it will work for invariant characters it will fail when you try
the same technique on variant characters and your code runs in a
different CCSID from the one in which you derived the hex value.
Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists
http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------
As an Amazon Associate we earn from qualifying purchases.