Vb.net 如何在VB中将包含引号的文本声明为字符串?

Vb.net 如何在VB中将包含引号的文本声明为字符串?,vb.net,Vb.net,以下是我需要声明为变量的文本: { "isReadOnly": false, "sku": "393A0001", "clientVersion": 3, "nuc": 2315038076, "nucleusPersonaId": 232865288, "nucleusPersonaDisplayName": "McFux", "nucleusPersonaPlatform": "360", "locale": "en-GB", "method": "idm", "priorityLevel"

以下是我需要声明为变量的文本:

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

使用双引号转义字符串中的引号

例如:

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

使用双引号转义字符串中的引号

例如:

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

在VB中,将引号对折以转义:

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

在VB中,将引号对折以转义:

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

要转义一个报价,只需添加另一个报价


=“{”isReadOnly“}”

要转义一个引号,只需添加另一个引号


=“{”isReadOnly“}”

我个人更喜欢使用函数为字符串添加引号,纯粹是为了可读性,尤其是在从变量构建字符串时

Function Qt(Byval str as String) as String

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

End Function
这样,
“{”“isReadOnly&”“false”“&sku&”“:…”
就变成了:

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

就个人而言,我更喜欢使用函数向字符串添加引号,纯粹是为了可读性,尤其是在从变量构建字符串时

Function Qt(Byval str as String) as String

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

End Function
这样,
“{”“isReadOnly&”“false”“&sku&”“:…”
就变成了:

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