strings包中的函数用法  参考链接http://studygolang.com/articles/88

1、strings.replace()

函数原型 func Replace(str1, old, str2, n int) string

//old是str1中的字符串,用str2替换str1中的old,一共替换n个。如果n<0,则全部替换

fmt.Println(strings.Replace("tet tet tet", "e", "es", 1))  //输出:test tet tet

fmt.Println(strings.Replace("tet tet tet", "e", "es", 2))  //输出:test test tet 

fmt.Println(strings.Replace("tet tet tet", "e", "es", -1)) //输出:test test test

相关文章:

  • 2021-08-22
  • 2021-07-19
  • 2021-06-11
  • 2022-12-23
  • 2022-02-20
  • 2021-12-22
  • 2022-02-23
  • 2022-01-27
猜你喜欢
  • 2021-07-24
  • 2022-03-03
  • 2022-12-23
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
相关资源
相似解决方案