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
+5.1k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+6.1k Golang : Missing Subversion command
+7.2k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+51.4k Golang : Check if item is in slice/array
+11.1k Golang : Create S3 bucket with official aws-sdk-go package
+42k Golang : How do I convert int to uint8?
+14.1k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+8k Swift : Convert (cast) String to Float
+8k Golang : Trim everything onward after a word
+29.6k Golang : Saving(serializing) and reading file with GOB
+8.9k Golang : Get final balance from bit coin address example