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
+4.5k Golang : fmt.Println prints out empty data from struct
+5.3k Golang : Extract sub-strings
+10k Golang : Concatenate (combine) buffer data example
+19.9k Golang : Convert string slice to struct and access with reflect example
+11.7k Generate salted password with OpenSSL example
+6.3k Golang : Create zip/ePub file without compression(use Store algorithm)
+20.8k Golang : Securing password with salt
+21.7k Golang : Randomly pick an item from a slice/array example
+8.6k Golang : Load ASN1 encoded DSA public key PEM file example
+17.8k Golang : Fix cannot download, $GOPATH not set error
+8.3k Golang : ffmpeg with os/exec.Command() returns non-zero status