I have a string that I'm pulling from a website, however, it has double quotes surrounding it and I'm trying to remove them. The string is for example:
" 54%"
I've tried:
strings.Trim(s[0], "\"")
But it's not removing the quotes.
Any help is much appreciated.
s := "\" hello\""
fmt.Println("Without trim: " + s)
// Without trim: " hello"
fmt.Println("Trim double quotes: " + strings.Trim(s, "\""))
// Trim double quotes: hello
Please give working code. Things that could be wrong:
Your code should work fine, perhaps you are misinterpreting some printed results or storing the wrong value?
ss := []string{"foo", `""`, `"bar"`, `" 54%"`}
for _, s := range ss {
t := strings.Trim(s, `"`)
fmt.Printf("OK: [%s] --> [%s]
", s, t)
}
// OK: [foo] --> [foo]
// OK: [""] --> []
// OK: ["bar"] --> [bar]
// OK: [" 54%"] --> [ 54%]
// │ │ │ │
// quotes ─┴───────────┘ │ │
// no quotes ──────────────────┴─────────┘