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
+24.1k Golang : Use regular expression to validate domain name
+12.9k Golang : Add ASCII art to command line application launching process
+10.3k Golang : Check a web page existence with HEAD request example
+37.6k Upload multiple files with Go
+9.2k Golang : Get curl -I or head data from URL example
+22.1k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+11.7k Golang : Surveillance with web camera and OpenCV
+7.2k Golang : Validate credit card example
+11.3k Golang : Fix - does not implement sort.Interface (missing Len method)
+16k Golang : Update database with GORM example
+22.8k Generate checksum for a file in Go
+7.6k Golang : Hue, Saturation and Value(HSV) with OpenCV example