· Mar 14

Adding " " to a string

Is it possible to add quotations " " so that it is part of the output?

For example:

set b = "Cat"

Set c = b

w c  giving an output of "Cat" as opposed to Cat.

Product version: IRIS 2021.2
Discussion (7)2
Log in or sign up to continue

I'm not entirely clear on the question you are asking - if you just need to add quotes to a string, you can do so by escaping with another quotation mark. For example,

set b = """Cat""" // That's 3 quotation marks in a row on each side: one to open/close the string, two to add the quote character to the string

set c = b

w c

If you are asking how to display the quotes without actually adding quotes to the string, I'm not sure if that's possible - would need a more experienced dev to chime in.

If you're asking what to do to only have one double-quote in the result, you could use this:

s b="""Cat"
w b

Basically, wherever you want a double-quote in the output string, put two double-quotes together in the string. So, if you wanted the string to say: Cat"so"only"one you would use this:

s b="Cat""so""only""one"

When I write code that needs to output comma separated value files, I often create variables to hold both the double-quote and comma characters, to me the resulting code is much easier to read. For example:

S Q="""",C=",",QCQ=Q_C_Q ; Sets Q to " char, C to comma, and QCQ to ","
; so when I need to output some strings, I just use the variables:
W Q_"string1"_QCQ_"string2"_QCQ_"string3"_Q,!

To me, it's easier to read than a whole bunch of imbedded double-quotes all strung together.

Hope this helps!