Question
· Jan 26, 2022

How to Concatenate Strings to create large string which contains"" inside in object script

Hi Developers,

I need to construct a string as xml which consists of "" in it.  As example below

set teststr ="<book id="bk105"><author type="old">Corets, Eva</author><title>The Sundered Grail</title><genre>Fantasy</genre></book>"

giving error in the area where " in middle of the string (highlighted in bold)

 

Could anybody suggest to me, how to construct a static string in object scripts with " in it?

Product version: Caché 2017.1
Discussion (4)1
Log in or sign up to continue

Hi Sreevani

In ObjectScript you can include a double-quote character inside a quoted string by doubling it up.

set teststr ="<book id=""bk105""><author type=""old"">Corets, Eva</author><title>The Sundered Grail</title><genre>Fantasy</genre></book>"

Since in this example, your string clearly contains html you might find that using single-quotes inside your string would be cleaner and easier to read, making it more maintainable:

set teststr ="<book id='bk105'><author type='old'>Corets, Eva</author><title>The Sundered Grail</title><genre>Fantasy</genre></book>"

George