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.7k PHP : Extract part of a string starting from the middle
+21k Golang : For loop continue,break and range
+15.4k Golang : invalid character ',' looking for beginning of value
+8.1k Golang : Qt splash screen with delay example
+4.7k Facebook : How to place save to Facebook button on your website
+39k Golang : How to iterate over a []string(array)
+5.4k Golang *File points to a file or directory ?
+8.7k Golang : Gorilla web tool kit schema example
+16.2k Golang : convert string or integer to big.Int type
+9.4k Golang : Get all countries currencies code in JSON format
+12.4k Golang : "https://" not allowed in import path
+13.4k Golang : Read XML elements data with xml.CharData example