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
+17k Golang : Read integer from file into array
+5.1k Golang : micron to centimeter example
+9.6k Golang : Apply Histogram Equalization to color images
+19.3k Golang : Execute shell command
+10.7k Golang : Flip coin example
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+14.6k Golang : Find network of an IP address
+10.8k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+7.4k Golang : alternative to os.Exit() function
+10.2k Golang : Compare files modify date example
+17.2k Golang : Get input from keyboard
+14k Golang : unknown escape sequence error