Adding a block of text to a string

In a shell I can do

a= << EOF

In xojo i want to create a block of text into a string such as

“requests”: [
“image”: {
“content”: “”

The only way I see is adding a string to a string for each line, and using “” for quotes this is tiresome if you have a lot of data. I do not want to import a file as i change many of the components in the string on the fly.

Is there such a command in the XOJO IDE for defining where a text section starts and ends like you can in B4X ?

No, but you can stick your text into a constant or use an array to build the string.

dim arr() as string = Array( _
    "line1", _
    "line2", _
    "line4" _
dim s as string = join( arr, EndOfLine )

Ah, yes, I missed that. In that case, a constant it better.

But your example is of JSON so why not use JSONItem or the new framework GenerateJSON? That way you’d only have to escape the quotes when the actual data contains them.

dim image as new Xojo.Core.Dictionary
image.Value( "content" ) = ""

dim requests() as auto
requests.Append image

dim json as new Xojo.Core.Dictionary
json.Value( "requests" ) = requests

dim jsonText as text = Xojo.Data.GenerateJSON( json )

If you prefer JSONItem (or my JSONItem_MTC):

dim image as new JSONItem
image.Value( "content" ) = ""

dim requests as new JSONItem
requests.Append image

dim json as new JSONItem
json.Value( "requests" ) = requests

dim jsonString as string = json.ToString

You can put it in an IDE constant and not have to worry about the escaping. I’m not sure if your JSON was just an example or you were looking for a JSON solution, but this applies to all large blocks of text, multiline and quotes okay.

Add a constant to your window, class, or whatever (can be done from the Insert menu, select Constant, or cmd-alt-C) and put in your value, then just use it in code like a placeholder.

dim sMultilineQuoteFilledBlob as String = kMyConstantName

But I mean, obviously if you’re trying to use JSON use a JSONItem.