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
+7k Golang : Levenshtein distance example
+36.4k Golang : Save image to PNG, JPEG or GIF format.
+43.5k Golang : Get hardware information such as disk, memory and CPU usage
+19k Golang : Display list of time zones with GMT
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+18.9k Golang : Read input from console line
+21k Golang : Sort and reverse sort a slice of strings
+17k Golang : Get number of CPU cores
+7.4k Linux : How to fix Brother HL-1110 printing blank page problem
+9.8k Golang : Get current, epoch time and display by year, month and day
+26k Mac/Linux and Golang : Fix bind: address already in use error