字符串去除空格和换行符
package main  
  
import (  
    "fmt"  
    "strings"  
)  
  
func main() {  
    str := "这里是 www\n.180it\n.com"  
    fmt.Println("-------- 原字符串 ----------")  
    fmt.Println(str)  
    // 去除空格  
    str = strings.Replace(str, " ", "", -1)  
    // 去除换行符  
    str = strings.Replace(str, "\n", "", -1)  
    fmt.Println("-------- 去除空格与换行后 ----------")  
    fmt.Println(str)  
}
输出结果为:
-------- 原字符串 ----------
这里是 www
.180it
.com
-------- 去除空格与换行后 ----------
这里是www.180it.com
如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!
 支付宝打赏
支付宝打赏
      微信打赏
微信打赏
     
txttool.com 说一段 esp56物联 查询128 IP查询