Golang : How to get quoted string into another string?
Problem :
You have a string and you want to join it with another string which is quoted. Somehow, you feel uncomfortable to escape the quotes in the string. So, what's the alternative solution?
Solution :
Use strconv.AppendQuote()
function. For example :
package main
import (
"fmt"
"strconv"
)
func main() {
//func AppendQuote(dst []byte, s string) []byte
dst := []byte("A quoted string looks like : ")
fmt.Println("Before : ", string(dst))
b := strconv.AppendQuote(dst, "this")
fmt.Println("After : ", string(b))
}
Output :
Before : A quoted string looks like :
After : A quoted string looks like : "this"
Reference :
https://www.socketloop.com/references/golang-strconv-appendquote-function-example
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+13.5k Golang : Save(pipe) HTTP response into a file
+30.1k Golang : Math pow(the power of x^y) example
+5k Golang : Shuffle array of list
+14.9k Golang : Find out mime type from bytes in buffer
+4.8k Golang : Struct field tags and what is their purpose?
+20.9k Golang : Read directory content with filepath.Walk()
+10.7k Golang : Gorilla web tool kit secure cookie example
+21.7k Golang : Gorilla mux routing example
+16.1k Golang : When to use init() function?
+18.2k Golang : Measure http.Get() execution time
+28.7k Get client IP Address in Go
+22.8k Golang : Find biggest/largest number in array