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
+10k Golang : Check if user agent is a robot or crawler example
+11.6k SSL : The certificate is not trusted because no issuer chain was provided
+18.3k Golang : Get path name to current directory or folder
+11.2k Golang : Simple image viewer with Go-GTK
+16.3k Golang : convert string or integer to big.Int type
+5k Golang : Constant and variable names in native language
+9.9k Golang : Turn string or text file into slice example
+17.6k Golang : Find smallest number in array
+18k Golang : Qt image viewer example
+14k Golang : How to check if a file is hidden?
+4.3k Javascript : How to show different content with noscript?
+12.3k Golang : Get remaining text such as id or filename after last segment in URL path