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
+29.2k Golang : Saving(serializing) and reading file with GOB
+8.4k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+7.8k Golang : What fmt.Println() can do and println() cannot do
+8.8k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+7.2k Golang : Accessing dataframe-go element by row, column and name example
+5.2k Golang : Generate Interleaved 2 inch by 5 inch barcode
+26.1k Golang : Convert(cast) string to uint8 type and back to string
+23.6k Golang : Fix type interface{} has no field or no methods and type assertions example
+23.4k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+8.2k Golang : Count leading or ending zeros(any item of interest) example
+14k Golang : syscall.Socket example
+8k Golang : HTTP Server Example