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
+12.8k Elastic Search : Mapping date format and sort by date
+7k Findstr command the Grep equivalent for Windows
+12.3k Golang : Verify token from Google Authenticator App
+17.9k Golang : Get current URL example
+11.1k Golang : calculate elapsed run time
+12.1k Golang : Read from buffered reader until specific number of bytes
+8.8k Golang : Translate language with language package example
+9.5k Golang : Create matrix with Gonum Matrix package example
+8.9k Golang : Channels and buffered channels examples
+4.5k Clean up Visual Studio For Mac installation failed disk full problem
+8.2k Random number generation with crypto/rand in Go
+4.2k Unix/Linux : secure copying between servers with SCP command examples