Replace single quote
Last Post 09 Nov 2007 08:52 PM by Barbara Morris. 8 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
Jim Butz
New Member
New Member
Posts:25

--
09 Nov 2007 02:17 PM
I need to export data (user names) but need to remove the single quote from any name (O'Reilly needs to be O Reilly or OReilly). I can't seem to be able to translate the quote to a blank because I cannot figure out how to define a single quote within a 'D' spec or a variable.
Wouter De saedeleer
Veteran Member
Veteran Member
Posts:575

--
09 Nov 2007 02:23 PM Accepted Answer
you can define a constant


D quote      C        Const(''')

Jim Butz
New Member
New Member
Posts:25

--
09 Nov 2007 02:28 PM Accepted Answer
I tried defining the constant as is but can't. I receive the SEU error below. D Quote C CONST(''') Character literal has missing trailing apostrophe;
TASullivan@BBDODetroit
Advanced Member
Advanced Member
Posts:412
Avatar

--
09 Nov 2007 04:18 PM Accepted Answer
try this:
D quote      C        Const(X'7D')
Jim Butz
New Member
New Member
Posts:25

--
09 Nov 2007 04:33 PM Accepted Answer
Great! Thanks.
Scott Klement
Editorial Staff Member
Editorial Staff Member
Posts:16319
Avatar

--
09 Nov 2007 04:49 PM Accepted Answer
The hex literal is okay if you know you'll always be running your code on a character set where x'7d' is a quote. But if you ever try to run it on a different character set where this isn't the case, you'll end up with the wrong value. I recommend that you avoid hard-coding the hex value of characters whenever possible. Instead, just code like this (note that it's 4 single quotes, not 3 like Frisky posted)

     D quote           c                   const('''') 
Presto! You have your single quote in a string.
Rory Hewitt
Veteran Member
Veteran Member
Posts:1311
Avatar

--
09 Nov 2007 05:56 PM Accepted Answer
The hex literal is okay if you know you'll always be running your code on a character set where x'7d' is a quote. But if you ever try to run it on a different character set where this isn't the case, you'll end up with the wrong value.
Scott, Since a single quote is an invariant character across all EBCDIC character sets, this isn't really a problem :) Rory
Scott Klement
Editorial Staff Member
Editorial Staff Member
Posts:16319
Avatar

--
09 Nov 2007 06:56 PM Accepted Answer
Since a single quote is an invariant character across all EBCDIC character sets, this isn't really a problem :)
Maybe. Unless you end up wanting to convert your code to run on an ASCII system somewhere down the line... or a Unicode system... Like I said, I'd avoid it where possible. I wouldn't issue an edict saying "never use hex codes", and I wouldn't go TOO far out of my way to avoid it. But I would avoid it wherever possible -- and this is one place where it's extremely easy to avoid.
Barbara Morris
Senior Member
Senior Member
Posts:5199

--
09 Nov 2007 08:52 PM Accepted Answer
Scott, Since a single quote is an invariant character across all EBCDIC character sets, this isn't really a problem :)
It's a problem if someone using VARPG asks how to code a quote, and someone recommends the X'7D' trick, or even sends them a handy copy file with some nice ready-to-use named constants. Anyway, I think x'7D' is an obfuscated way of defining a quote, and I would recommend against it even if it was an invariant character in all possible code pages including Klingon43. If there's a possibility of someone being confused by the 4 quotes in the named constant definition, add a comment to reassure them.

 * QUOTE defines a single quote (apostrophe) character. 
 * Note: It can't be coded as ''' because RPG requires single quotes 
 * to be doubled up inside literals.
D QUOTE             c                               ''''
You are not authorized to post a reply.

Acceptable Use Policy