I have a string
{"function":"TrainingQuestionInfo","values":{"Question":"текст со спецсимволами / \ и т.д."}} I need to escape quotes and slashes.
How to do it? Is there any function for this?
I have a string
{"function":"TrainingQuestionInfo","values":{"Question":"текст со спецсимволами / \ и т.д."}} I need to escape quotes and slashes.
How to do it? Is there any function for this?
https://golang.org/pkg/strconv/#Quote
fmt.Println (strconv.Quote ( {"function":"TrainingQuestionInfo","values":{"Question":"текст со спецсимволами / \ и т.д."}} ))
Escaping usually depends on where this string is sent.
For example, you can use JSON:
b, err := json.Marshal("aaa\nbbbыыы") fmt.Printf("str=`%v`, err=%v\n", string(b), err) // выводит str=`"aaa\nbbbыыы"`, err=<nil> \\ for a slash, \" for quotation marks. Everything is as it is ... PS. Automation of the solution - first replacing all the slashes, then - quotes.
From String Literals ( http://golang.org/ref/spec#String_literals ):
But if your multi-line string must include backquote (`), then you will have to use an interpreted string literal:
`line one line two ` + "`" + `line three line four` You cannot directly put backquote ( ) в строковый литерал строки ( xx). You should use (as explained in how to put a return quote in the string to return to its original position "):
Source: https://ru.stackoverflow.com/questions/479759/
All Articles