内容简介:函数声明:官方描述:示例代码:
函数声明:
func Trim(s string, cutset string) string
官方描述:
返回将 s 前后端所有 cutset 包含的 utf-8 码值都去掉的字符串。
示例代码:
package main import ( "fmt" "strings" _ "test/subpac" ) func main(){ fmt.Println("[ !!! Achtung! Achtung! !!! ]:[]:[", strings.Trim(" !!! Achtung! Achtung! !!! ", "") ,"\b]") fmt.Println("[ !!! Achtung! Achtung! !!! ]:[ ]:[", strings.Trim(" !!! Achtung! Achtung! !!! ", " ") ,"\b]") fmt.Println("[ !!! Achtung! Achtung! !!! ]:[!]:[", strings.Trim(" !!! Achtung! Achtung! !!! ", "!") , "\b]") fmt.Println("[ !!! Achtung! Achtung! !!! ]:[! ]:[", strings.Trim(" !!! Achtung! Achtung! !!! ", "! "), "\b]" ) }
输出结果:
[ !!! Achtung! Achtung! !!! ]:[]:[ !!! Achtung! Achtung! !!! ] [ !!! Achtung! Achtung! !!! ]:[ ]:[ !!! Achtung! Achtung! !!!] [ !!! Achtung! Achtung! !!! ]:[!]:[ !!! Achtung! Achtung! !!! ] [ !!! Achtung! Achtung! !!! ]:[! ]:[ Achtung! Achtung]
第一行 cutset 为空(不是空格):因此输出原字符串。
第二行 cutset 为 ” “(空格):因此串首尾的两个空格字符被删除了。
第三行 cutset 为 “!” :收尾未匹配到该 cutset,因此输出原字符串。
第四行 cutset 为 “! “:首先匹配到空格,串首尾空格字符被删除,然后匹配到 “!”,继续删除首尾的各三个 “!”,于是得到该结果串。
注:输出结果多余的空格是因为 Println 在输出多个串时会在串之间添加空格。如下:
fmt.Println("123", "456", "789")
输出:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- KotterKnife 库中 Kotlin 高级用法介绍
- C++ STL容器——stack用法介绍
- Django model update的各种用法介绍
- AWK 的用法
- AWK基础用法
- UniversalImageLoader的用法总结
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Probability and Computing
Michael Mitzenmacher、Eli Upfal / Cambridge University Press / 2005-01-31 / USD 66.00
Assuming only an elementary background in discrete mathematics, this textbook is an excellent introduction to the probabilistic techniques and paradigms used in the development of probabilistic algori......一起来看看 《Probability and Computing》 这本书的介绍吧!