package main

import (
    "fmt"
    "strings"
)

func main() {
    str := "welcome to cn\nbattle\n.com"
    // 去除空格  
    str = strings.Replace(str, " ", "", -1)
    // 去除换行符  
    str = strings.Replace(str, "\n", "", -1)
    fmt.Println(str)
}
来源:中战博客,欢迎分享!
标签: go,golang,string,replace