> -----Original Message-----
> From: Schlosser, Robert J [mailto:[log in to unmask]]
>
> I have a need to scan several lines of JCL some of which may
> include either single or double quotes, [...]
> The problem is that any of the standard ways of cleaning up a
> line before processing it don't work! Things I've tried include:
>
> setvar s "Here's an example of a string with a single quote in it! "
> echo !s
> setvar s3 repl(!s,"'"," ") These work fine for a string with
> ONLY a single instance of a single quote - we can use the
> double quotes to surround it.
"echo" is a red-herring here: it forces you to "believe" that "!" characters are needed everywhere, and they AREN'T! [well, except here ;)]
"in the context of an expression", variables are variables, so you DON'T need to use the "!" to expand a variable to it's value BEFORE processing it. "echo" is weird in that it echos a literal string, not an expression, so you DO need it for ECHO.
For instance, after setting the variable "S" above, note the difference in these two commands:
:setvar s "Here's an example of a string with a single quote in it! "
:echo !s
Here's an example of a string with a single quote in it!
:calc s
Here's an example of a string with a single quote in it!
:calc !s
calc Here's an example of a string with a single quote in it!
^
Variable name encountered, but variable is not defined. (CIERR 9805)
SETVAR is an "expression context", so you don't need the "!":
:setvar s3 repl(s,"'"," ")
:calc s3
Here s an example of a string with a single quote in it!
:setvar s3 '"'+!s+'"'
setvar s3 '"'+Here's an example of a string with a single quote in it! +'"'
^
Variable name encountered, but variable is not defined. (CIERR 9805)
(whups, I didn't see the EXTRA set of double quotes you added)
:setvar s3 '"'+"!s"+'"'
:calc s3
"Here's an example of a string with a single quote in it! "
> However, put it in a pair of double quotes, and it doesn't
> work! (Similarly for any line with both types of quotes!)
>
> setvar s3 '"'+"!s"+'"'
> calc pos(!s3,"'") returns 0, rather than 6!
You're right:
:calc pos(!s3,"'")
0, $0, %0
:calc pos(s3,"'")
0, $0, %0
however you have the POS parameters BACKWARDS:
:calc pos("'",s3)
6, $6, %6
[and note: no !]
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|