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
+12.3k Golang : Pass database connection to function called from another package and HTTP Handler
+7.2k SSL : How to check if current certificate is sha1 or sha2 from command line
+9.2k Golang : Find correlation coefficient example
+16.7k Golang : How to tell if a file is compressed either gzip or zip ?
+17.9k Golang : Get download file size
+10.8k Golang : Fix fmt.Scanf() on Windows will scan input twice problem
+6.9k Linux : How to fix Brother HL-1110 printing blank page problem
+34.8k Golang : Strip slashes from string example
+23.2k Golang : Fix type interface{} has no field or no methods and type assertions example
+12k Golang : Search and extract certain XML data example
+10.1k Golang : ISO8601 Duration Parser example
+13.5k Golang : convert rune to unicode hexadecimal value and back to rune character