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
+6.3k Golang : Embedded or data bundling example
+31.8k Golang : Math pow(the power of x^y) example
+5.8k Golang : Experimenting with the Rejang script
+30.1k Golang : How to redirect to new page with net/http?
+6.4k Golang : Humanize and Titleize functions
+21.5k Golang : How to reverse slice or array elements order
+7.2k Golang : Gorrila set route name and get the current route name
+5.2k Clean up Visual Studio For Mac installation failed disk full problem
+6.2k Golang : How to determine if request or crawl is from Google robots
+5.9k Linux/Unix : Commands that you need to be careful about
+5.5k Golang : Find change in a combination of coins example