用Go语言进行chomp操作

package main

import (
    "fmt"
    "strings"
)

func main() {
    foo := "hooo\n"
    bar := "bar\n"

    fmt.Printf("foo is %s bar is %s", foo, bar)
    // foo is hooo
    // bar is bar
    foo = strings.TrimRight(foo, "\n")
    bar = strings.TrimRight(bar, "\n")

    fmt.Printf("foo is %s bar is %s", foo, bar)
    // foo is hooo bar is bar
}
广告
将在 10 秒后关闭
bannerAds