strings.TrimRight()
works just fine. The "problem" in your case is that the string
value stored in the a
variable does not end with "\r\n"
.
The reason for that is because you "quote" it using fmt.Sprintf()
, and the string will end with "\\r\\n"
, and additionally even a double quotation mark will be added to it (that is, it ends with a backslash, the letter r
, another backslash, the letter n
and a double quote character).
If you don't quote your string, then:
var s = "\b\x02\b\x02\r\n"
fmt.Printf("s: %q\n", s)
b := strings.TrimRight(s, "\r\n")
fmt.Printf("b: %q\n", b)
Output (try it on the Go Playground):
s: "\b\x02\b\x02\r\n"
b: "\b\x02\b\x02"