View previous topic :: View next topic
|
Author |
Message |
Mike 1304
New User
Joined: 15 Oct 2011 Posts: 46 Location: Germany
|
|
|
|
Hi,
I have to handle a string, which may contain single quote ' and double quote " (shift 2), it also may contain two singe quotes ('') or 2 double quotes ("").
Maybe I'll take the risk and translate a ' to x'EF' and translate it back afterwards.
My question: Is there a smarter way to handle it? |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Totally depends on what processing you are doing on the string. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
Maybe I'll take the risk and translate a ' to x'EF' and translate it back afterwards. |
while writing a JCL analyzer as an EDIT macro I was I was faced with the same problem when dealing with JCL statements containing it ,
both for the ' and the&
since I was not on research/investigate mood
I took the lazy road of translating them to x'FF' and x'FE'
never faced any issues.
but using rexx You have the also the advantage that strings can be delimited using "
to keep it short You can safely use the translate trick |
|
Back to top |
|
|
Mike 1304
New User
Joined: 15 Oct 2011 Posts: 46 Location: Germany
|
|
|
|
Thanks Enrico,
I'll do it, even it it not so sure as your example with JCL.
My Input is a COBOL Program source code und hex values make more sense here as in a JCL.
@Nic: Have you any hint, knowing now it's cobol source?
Mike |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
You could also, as Dr. Sorichetti intimates, take advantage of the fact that both single and double quotes are allowed as delimiters in Rexx.
Thus, suppose you are searching for the token "'FOOBAR'" (i.e., delimited by single quotes). A possible code fragment might be:
Code: |
single_quote = "'"
schwing = single_quote || 'FOOBAR' || single_quote
if (pos(schwing,string)=0) then call home
else call girl |
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
regardless of the source type,
dealing with single and double quotes in rexx can be a challange
as they almost require an escape code to deal with.
extra KEYWORDS are required to qualify the data value.
because you are dealing with data values in the rexx program.
most people i know use Enrico's method
to deal with single and double quotes
when they are part of the character text being manipulated. |
|
Back to top |
|
|
|