当前位置:网站首页>Golang 字符串分割,替换和截取
Golang 字符串分割,替换和截取
2022-07-03 08:04:00 【Bel_Ami同学】
package main
import (
"fmt"
"strings"
)
func main() {
str := "赵,钱,孙,李,赵"
//字符串分割, 使用字符分割
str1 := strings.Split(str, ",")
fmt.Println(str1[0]) //赵
fmt.Println(str1[1]) //钱
fmt.Println(str1[2]) //孙
fmt.Println(str1[3]) //李
fmt.Println(str1[4]) //赵
//字符串替换, -1表示全部替换, 0表示不替换, 1表示替换第一个, 2表示替换第二个...
str2 := strings.Replace(str, "赵", "钱", -1)
fmt.Println(str2) //钱,钱,孙,李,钱
//字符串截取, 一个汉字3个字节, 还有一个逗号
str3 := str[4 : len(str)-4]
fmt.Println(str3) //钱,孙,李
}
边栏推荐
- Wechat applet taro learning record
- the installer has encountered an unexpected error installing this package
- JS to implement publish and subscribe
- A tunnel to all ports of the server
- Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
- Redis profile
- YOLO系列 --- xml2txt脚本
- 超限黑客认知
- Huawei switch: configure Telnet, SSH and web access
- haproxy+keepalived集群搭建02
猜你喜欢
Shader foundation 01
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
一个实习生的CnosDB之旅
Transfinite hacker cognition
数据的存储
JS common basic case sorting (continuous update)
Lua framwrok framework starts
About the problem that the editor and the white screen of the login interface cannot be found after the location of unityhub is changed
C语言-入门-精华版-带你走进编程(一)
WorldView卫星遥感影像数据/米级分辨率遥感影像
随机推荐
Install cross compiler arm none liunx gnueabihf
Zohocrm deluge function application time verification
Microsoft Security Response Center
tslib库的移植
An intern's journey to cnosdb
What is a data type? What is the use of data types?
P1896 [scoi2005] non aggression (shape pressure DP)
An article for you to understand - Manchester code
the installer has encountered an unexpected error installing this package
P2704 [NOI2001] 炮兵阵地(状压dp)
VMware virtual machine configuration static IP
JSON与Object之间转换
Unity XR realizes interaction (grasping, moving, rotating, transmitting, shooting) -pico
Editor Extensions
Quelle est la définition? Qu'est - ce qu'une déclaration? Quelle est la différence?
RM delete file
Basic operation and process control
Technical dry goods | Bert model for the migration of mindspore NLP model - text matching task (2): training and evaluation
Wechat native applet cloud development learning record 01
Conversion between JSON and object