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
+10.9k Golang : Characters limiter example
+7.6k Golang : Check from web if Go application is running or not
+31.8k Golang : Copy directory - including sub-directories and files
+7.2k Golang : Shuffle strings array
+7.9k Golang : Oanda bot with Telegram and RSI example
+5.2k Golang : Frobnicate or tweaking a string example
+24.6k Golang : Storing cookies in http.CookieJar example
+5.5k Golang : Denco multiplexer example
+17.9k Golang : Get path name to current directory or folder
+5.6k Facebook : How to force facebook to scrape latest URL link data?