【发布时间】:2017-06-05 19:43:08
【问题描述】:
在 golang 中,如何删除两个字母之间的引号,如下所示:
import (
"testing"
)
func TestRemoveQuotes(t *testing.T) {
var a = "bus\"zipcode"
var mockResult = "bus zipcode"
a = RemoveQuotes(a)
if a != mockResult {
t.Error("Error or TestRemoveQuotes: ", a)
}
}
功能:
import (
"fmt"
"strings"
)
func RemoveQuotes(s string) string {
s = strings.Replace(s, "\"", "", -1) //here I removed all quotes. I'd like to remove only quotes between letters
fmt.Println(s)
return s
}
例如:
"bus"zipcode" = "bus 邮编"
【问题讨论】:
-
问题是引号是成对的,并且在字母之间没有任何关系,除非字母是引号的分隔符。即使这样也没有实际意义,因为在
aadsfsdf""""asdf中,没有任何变化。