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
+16.7k Swift : Convert (cast) Int to int32 or Uint32
+4.3k List of Golang XML tutorials
+15.6k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+8.3k Golang : Fix go.exe is not compatible with the version of Windows you're running
+9.2k Golang : Get remaining text such as id or filename after last segment in URL path
+17.3k Golang : Underscore or snake_case to camel case example
+30.8k Golang : All update packages with go get command
+8.2k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+14.6k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+4.4k PHP : Proper way to get UTF-8 character or string length
+3.5k Google : Block or disable caching of your website content
+7.7k Facebook : Getting the friends list with PHP return JSON format