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
+14.3k Golang : Rename directory
+10.8k Golang : Proper way to test CIDR membership of an IP 4 or 6 address example
+13.9k Golang : syscall.Socket example
+14.6k Golang : Submit web forms without browser by http.PostForm example
+35.7k Golang : Converting a negative number to positive number
+9.7k Golang : Channels and buffered channels examples
+7.3k SSL : How to check if current certificate is sha1 or sha2 from command line
+15.7k Golang : Get file permission
+5.2k Gogland : Datasource explorer
+7.2k Golang : How to stop user from directly running an executable file?
+26.4k Golang : How to check if a connection to database is still alive ?