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.3k Golang : Secure file deletion with wipe example
+9.6k Golang : concatenate(combine) strings
+6.3k Golang : How to determine if user agent is a mobile device example
+2.5k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+5k Golang : zlib compress file example
812 Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
+10.1k Golang : Check if os.Stdin input data is piped or from terminal
+8.3k Golang : Basic authentication with .htpasswd file
+5.9k Facebook : Getting the friends list with PHP return JSON format
+7.1k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+2.4k Golang : Check if password length meet the requirement
+3.3k Golang : Tell color name with OpenCV example