mirror of
https://github.com/teivah/100-go-mistakes.git
synced 2026-06-20 16:45:56 +08:00
16 lines
282 B
Go
16 lines
282 B
Go
package main
|
|
|
|
import "strings"
|
|
|
|
func removeNewLineSuffixes(s string) string {
|
|
if s == "" {
|
|
return s
|
|
}
|
|
if strings.HasSuffix(s, "\r\n") {
|
|
return removeNewLineSuffixes(s[:len(s)-2])
|
|
}
|
|
if strings.HasSuffix(s, "\n") {
|
|
return removeNewLineSuffixes(s[:len(s)-1])
|
|
}
|
|
return s
|
|
}
|