1. 字符串常見方法
1.1 字符串三種比較方法
fmt.Println("go"=="go")
fmt.Println("GO"=="go")
fmt.Println(strings.Compare("GO","go"))
fmt.Println(strings.Compare("go","go"))
fmt.Println(strings.EqualFold("GO","go"))
輸出
true
false
-1
0
true
1.2 字符串替換
var dstpathtmp_no_module = strings.Replace(dstpathtmp, dstpathtmp[comma:], "", -1)
1.3 字符串截取
comma := strings.LastIndex(dstpathtmp, "/")
結果:
dstpathtmp如果爲system/lib/binderxxx,那麼
dstpathtmp[comma:] 爲/binderxxx
dstpathtmp[comma+1:] 爲binderxxx
1.4 字符串包含
var s string = "hello go"
r := strings.Contains(s, "go")
fmt.Println(r)
1.5 串聯
s3 := strings.Repeat(s, 2)
fmt.Println(s3)
1.6 按空格返回切片數組
s7 := " hello go "
s8 := strings.Fields(s7)
fmt.Println(s8)
1.7 去除兩端字符
s6 := strings.Trim(s, "o")
fmt.Println(s6)
2. 函數
2.1 函數定義和調用
func CheckFileContainsStr(filepath ,str string) bool {
...
return false
}