1

I have string that is formatted in UTF-8.

"{""messages"":[{""messageId"":""245043"",""campaignId"":""14085""

I need to replace the double double quotes to single double quotes.

The following is able to replace double quotes to double single quotes

        NewMessage = Replace(Message, "““", "''")

But I can't figure out how to replace the double double quotes to single double quotes.

The code was written in vb.net and the desired output is:

"{"messages":[{"messageId":"245043","campaignId":"14085"

Added image from watch

enter image description here

Solution Provided by o_O

enter image description here

Internet Engineer
  • 2,514
  • 8
  • 41
  • 54

2 Answers2

0

You can leverage the Chr function for this:

NewMessage = Message.Replace(Chr(34) & Chr(34), Chr(34))
NoAlias
  • 9,218
  • 2
  • 27
  • 46
0

I assume your data is coming from somewhere in
"{""messages"":[{""messageId"":""245043"",""campaignId"":""14085""
format, so for the sake of the question I'm formatting the input in a proper way:

Dim str As String  =  """{""""messages"""":[{""""messageId"""":""""245043"""",""""campaignId"""":""""14085"""""
Console.WriteLine("Input : " & str)
str = str.Replace("""","'").Replace("''","""").Replace("'","""")
Console.WriteLine("Output : " & str)

Output:

Input : "{""messages"":[{""messageId"":""245043"",""campaignId"":""14085""

Output : "{"messages":[{"messageId":"245043","campaignId":"14085"

Check it on Fiddle

boop_the_snoot
  • 3,209
  • 4
  • 33
  • 44
  • Yes! 100%, your solution works when you provide the string. I will post image of what happens with your solution when applied to my string. – Internet Engineer Sep 15 '17 at 17:48