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.4k Golang : Convert file unix timestamp to UTC time example
+13.3k Golang : Determine if directory is empty with os.File.Readdir() function
+26.2k Golang : Create x509 certificate, private and public keys
+4.1k Linux : How to fix Brother HL-1110 printing blank page problem
+3k Golang : Calculate half life decay example
+4.9k Golang : Get YouTube playlist
+5.5k Setting $GOPATH environment variable for Unix/Linux and Windows
+34.8k Golang : Marshal and unmarshal json.RawMessage struct example
+20.4k Golang : Force your program to run with root permissions
+35.3k Golang : Convert string to array/slice
+2.9k JavaScript/JQuery : Redirect page examples
+4.7k Golang : Decode XML data from RSS feed