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
+5k Golang : Compound interest over time example
+4.9k Golang : List all packages and search for certain package
+6.5k Golang : What fmt.Println() can do and println() cannot do
+6.9k Golang : Handle Palindrome string with case sensitivity and unicode
+24.2k Golang : How to read integer value from standard input ?
+10.7k Golang : Perform sanity checks on filename example
+5.3k Golang : Map within a map example
+8k Golang : Serving HTTP and Websocket from different ports in a program example
+5.8k How to let Facebook Login button redirect to a particular URL ?
+37.8k Golang : How to iterate over a []string(array)
+6.3k Golang : Word limiter example
+23.4k Golang : convert rune to integer value