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.1k Golang : Record voice(audio) from microphone to .WAV file
+6.7k Golang : Normalize email to prevent multiple signups example
+18.3k Golang : Find IP address from string
+3.1k Golang : Fix go-cron set time not working issue
+17.2k Golang : Multi threading or run two processes or more example
+8.4k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+11.8k Golang : Save webcamera frames to video file
+31.2k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+17.4k Golang : Upload/Receive file progress indicator
+47.7k Golang : How to convert JSON string to map and slice
+21.9k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+6.6k Android Studio : Hello World example