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
+5.7k Golang : Function as an argument type example
+9.4k Golang : Detect number of active displays and the display's resolution
+20k nginx: [emerg] unknown directive "passenger_enabled"
+9.4k Golang : Populate slice with sequential integers example
+9.6k Golang : Get current, epoch time and display by year, month and day
+4.5k MariaDB/MySQL : Form select statement or search query with Chinese characters
+8.7k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+9.9k Golang : Get login name from environment and prompt for password
+4.3k Javascript : Detect when console is activated and do something about it
+4.8k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+6.6k Fix sudo yum hang problem with no output or error messages
+4.5k Unix/Linux : How to pipe/save output of a command to file?