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
+7.9k Golang : Gaussian blur on image and camera video feed examples
+8k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+5.4k Golang : Process non-XML/JSON formatted ASCII text file example
+12.3k Facebook PHP getUser() returns 0
+3.7k Golang : Valued expressions and functions example
+12.3k Swift : Convert (cast) Int to String ?
+4.8k Linux/Unix/PHP : Restart PHP-FPM
+4.6k Golang : Reclaim memory occupied by make() example
+4.4k Swift : Convert (cast) Float to Int or Int32 value
+8.1k Golang : Get SPF and DMARC from email headers to fight spam
+5.2k Golang : How to verify input is rune?
+31k Golang : Validate email address with regular expression