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
+18.6k Golang : Read binary file into memory
+18.1k Golang : Simple client server example
+6.3k Golang : Scan forex opportunities by Bollinger bands
+15.5k Golang : Get query string value on a POST request
+12.6k Golang : Encrypt and decrypt data with x509 crypto
+6k Golang : Detect variable or constant type
+6.2k Golang : Compound interest over time example
+12.1k Golang : GTK Input dialog box examples
+8.6k Your page has meta tags in the body instead of the head
+32.8k Golang : Copy directory - including sub-directories and files
+10k Golang : interface - when and where to use examples
+9k Yum Error: no such table: packages