David Sproat
David Sproat

Reputation: 13

How do I declare this text containing quotes as a string in VB?

Here is the text I need to declare as a variable:

{ "isReadOnly": false, "sku": "393A0001", "clientVersion": 3, "nuc": 2315038076, "nucleusPersonaId": 232865288, "nucleusPersonaDisplayName": "McFux", "nucleusPersonaPlatform": "360", "locale": "en-GB", "method": "idm", "priorityLevel":4, "identification": { "EASW-Token": "" } }

Upvotes: 1

Views: 307

Answers (4)

bendataclear
bendataclear

Reputation: 3850

Personally I prefer to use a function to add quotes to a string, purely for readability, especially when building a string from variables.

Function Qt(Byval str as String) as String

    Return """" & str & """"

End Function

That way "{ """ & isReadOnly & """: false, """ & sku & """: ..." becomes:

"{ " & Qt(isReadOnly) & ": " & false & ", " & Qt(sku) & ": ..."

Upvotes: 2

Gary
Gary

Reputation: 2916

To escape a quote you just need to add another quote.

="{ ""isReadOnly""}"

Upvotes: 0

futankamon
futankamon

Reputation: 125

Use double quotes to escape the quotes in the string.

For example:

Dim s = "{ ""isReadOnly"": false, ""sku"": ..."

Upvotes: 2

ekolis
ekolis

Reputation: 6776

In VB, you double up the quotes to escape them:

"{ ""isReadOnly"": false, ""sku"": ""393A0001"", ..."

Upvotes: 1

Related Questions