0%

Trim

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package main

import (
"fmt"
"strings"
)

func main() {
//返回去掉字符串s前端和后端**所有**cutset子串的字符串;
fmt.Println(strings.Trim("top这里是top www.xmge.toptop", "top"))
//返回去掉字符串s前端**所有**cutset子串的字符串;
fmt.Println(strings.TrimLeft("baba", "ba"))
//返回去掉字符串s后端**所有**cutset子串的字符串;
fmt.Println(strings.TrimRight("baba", "ab"))
//返回去掉字符串s的前缀prefix子串的字符串;
fmt.Println(strings.TrimPrefix("baba", "ba"))
//返回去掉字符串s的后缀prefix子串的字符串;
fmt.Println(strings.TrimSuffix("baba", "a"))
//判断字符串s是否有前缀字符串prefix;类似python的startswith
fmt.Println(strings.HasPrefix("hello", "he"))
//判断字符串s是否有后缀字符串prefix;类似python的endswith
fmt.Println(strings.HasSuffix("world", "ld"))
}
1
2
3
4
5
6
7
这里是top www.xmge.


ba
bab
true
true