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
+19.6k Golang : How to force compile or remove object files first before rebuild?
+12.7k Golang : Query string with space symbol %20 in between
+15.9k Golang : Get own process identifier
+18.7k Golang : Convert seconds to human readable time format example
+6.2k Golang : Takes a plural word and makes it singular
+4k Unix/Linux : How to pipe/save output of a command to file?
+6.7k Golang : Get YouTube playlist
+16.9k Golang : How to log each HTTP request to your web server?
+3.7k Javascript : How to show different content with noscript?
+11k Golang : Convert decimal number(integer) to IPv4 address
+10.9k Golang : Gorilla web tool kit secure cookie example
+8.2k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference