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
+11.2k Golang : Create S3 bucket with official aws-sdk-go package
+40.3k Golang : UDP client server read write example
+11.9k Golang : How to detect a server/machine network interface capabilities?
+10.1k CodeIgniter : Load different view for mobile devices
+6.5k CodeIgniter : form input set_value cause " to become & quot
+15k Golang : Find commonalities in two slices or arrays example
+23.3k Golang : Print out struct values in string format
+13.2k Golang : List objects in AWS S3 bucket
+10.1k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+28.4k Golang : Connect to database (MySQL/MariaDB) server
+4.9k Golang : How to pass data between controllers with JSON Web Token
+7.1k Golang : constant 20013 overflows byte error message