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
+7.8k Golang : Random integer with rand.Seed() within a given range
+10.2k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+4.8k Fix fatal error: evacuation not done in time problem
+8.3k Golang : Scramble and unscramble text message by randomly replacing words
+6.5k Golang : How to convert strange string to JSON with json.MarshalIndent
+12.3k Golang : Get dimension(width and height) of image file
+26.6k Get file path of temporary file in Go
+16.2k Golang : Qt image viewer example
+21.5k Golang : simulate tail -f or read last line from log file example
+17.9k Golang : Fix cannot download, $GOPATH not set error
+7.9k Golang : GMail API create and send draft with simple upload attachment example
+8.5k Golang : Get all countries currencies code in JSON format