Re: escaping a quotation mark from within an NCL string

From: Jonathan Vigh <vigh_at_nyahnyahspammersnyahnyah>
Date: Wed, 11 Mar 2009 16:28:59 +0000

Hi Mary,
   Okay, thanks for letting me know. I wonder if there'd be any way to
come up with a verbatim-type function which assigns everything inside it
to a string, e.g.
 
stringy = verbatim("This, that, "'" ' ', and the other thing)
print(stringy)

result:
"This, that, "'" ' ', and the other thing

Thanks,
   Jonathan

Mary Haley wrote:
> Jonathan,
>
> I'm afraid there's no way to this other than using the special "quote"
> variable you set up.
>
> Just today I was asking about being able to use single ticks to
> represent characters, like:
>
> quote = '"'
>
> so that you at least don't need to to the "inttochar" thing. It's not
> a huge priority; just something we were discussing.
>
> I think part of the problem is that we don't have any characters to
> use as an escape
> character. The "\" is a valid character in NCL, so it can't be used.
>
> I'll have to let Dave Brown weigh in further here.
>
> --Mary
>
> On Mar 10, 2009, at 6:31 PM, Jonathan Vigh wrote:
>
>>
>> Greetings,
>> Hopefully this is an easy question . . . I'm wondering if it is
>> possible to escape a quotation mark within a string in NCL, similar to
>> what is done for the shell in command line options (or calls using
>> systemfunc) using "\" or single quote marks. The reason I'd like to do
>> this is that I'm writing NCL code to dynamically generate more NCL code,
>> and I'd like to be able to put a quotation mark in the resulting string.
>>
>> Right now, one solution is to add a quotation mark character to the
>> string every place I want a quotation mark to appear in the resulting
>> output string, otherwise NCL gets confused and interprets the desired
>> quotation mark as terminating the current string. A really simple
>> example is:
>>
>> quote = inttochar(34)
>>
>> module_contents = " fin = addfile(processed_data_directory +
>> processed_filelist_at_array(istorm), "+quote+"r"+quote+") ; open input
>> file" + cr \
>>
>> which will generate the following line of code in the module:
>>
>> fin = addfile(processed_data_directory +
>> processed_filelist_at_array(istorm), "r") ; open input file
>>
>> Obviously, this could get really tricky for a complicated expression
>> with many quotes. So I'm wondering if there is a way to escape the
>> quotation mark within an NCL string? Enclosing the whole thing in single
>> quotes doesn't seem to work.
>>
>> Thanks,
>> Jonathan
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
Received on Wed Mar 11 2009 - 10:28:59 MDT

This archive was generated by hypermail 2.2.0 : Thu Mar 12 2009 - 14:10:21 MDT