Quote character (") in strings
Mike German
I get strings obtained from an api in json format for example
{"orbname":"20231004_000213.515_BE_UK"}\n{"orbname":"20231004_001652.467_UK"}\n I want to extract all entries such as 20231004_000213.515_BE_UK etc
I have tried things like
dummy = StringFromList(5,response,":")
dummy = ReplaceString("orbname",response,"")
dummy = ReplaceString("}\n{",dummy,";")
dummy = ReplaceString("orbname",response,"")
dummy = ReplaceString("}\n{",dummy,";")
where response is the string from the api. The problem with this is that the quote characters remains in the string. How can quotes within a string be removed from the string? Previously I have done this sort of thing by using a loop and search strings and something like outputString = response[pos1,pos2] but am looking for a neater way to do it perhaps with lists or similar. I don't particualrly want get involved in json.
A quote mark in a string must be escaped to survive as something other than the start or end of a string:
•print junk
"orbname":"something"
•print replacestring("\"orbname\"", junk, "")
:"something"
October 4, 2023 at 10:39 am - Permalink
Thanks John - it's easy when you know how :-)
October 6, 2023 at 02:00 am - Permalink
Yeah- escaping quote marks can get pretty hairy if the strings will pass through multiple layers of interpretation. I've seen some pretty unreadable examples when composing a string to pass from Igor's command line to ExecuteScriptText, where both Igor and the OS are going to take a crack at interpreting quote marks.
DisplayHelpTopic "Escape Sequences in Strings"
October 6, 2023 at 10:09 am - Permalink
Fortunately its not now proving too difficult for me. The debugging view of strings seems quite accurate and helps.
October 9, 2023 at 04:12 am - Permalink