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.9k Cash Flow : 50 days to pay your credit card debt
+4.3k Golang *File points to a file or directory ?
+45.6k Golang : Convert int to byte array([]byte)
+11.2k Golang : How to check if a string starts or ends with certain characters or words?
+31.3k Golang : How to check if a date is within certain range?
+8.6k Golang : Eroding and dilating image with OpenCV example
+19.8k Golang : For loop continue,break and range
+16.2k Golang : Multi threading or run two processes or more example
+20.7k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+13.3k Golang : How to filter a map's elements for faster lookup
+5.6k Golang : Calculate diameter, circumference, area, sphere surface and volume
+18.6k Golang : Append content to a file