当前位置:网站首页>Golang string segmentation, substitution and interception
Golang string segmentation, substitution and interception
2022-07-03 08:13:00 【Bel_ AMI classmate】
package main
import (
"fmt"
"strings"
)
func main() {
str := " Zhao , money , Grandchildren , Li , Zhao "
// String segmentation , Use character segmentation
str1 := strings.Split(str, ",")
fmt.Println(str1[0]) // Zhao
fmt.Println(str1[1]) // money
fmt.Println(str1[2]) // Grandchildren
fmt.Println(str1[3]) // Li
fmt.Println(str1[4]) // Zhao
// String substitution , -1 Means replace all , 0 Means not to replace , 1 Replace the first one , 2 Means to replace the second ...
str2 := strings.Replace(str, " Zhao ", " money ", -1)
fmt.Println(str2) // money , money , Grandchildren , Li , money
// String interception , A Chinese character 3 Bytes , There is also a comma
str3 := str[4 : len(str)-4]
fmt.Println(str3) // money , Grandchildren , Li
}
边栏推荐
- A tunnel to all ports of the server
- LinkList
- Abstract classes and interfaces
- Product creation and commercial realization of chat robot (according to La Ma Bang - Dr. Wang Jingjing - speech)
- WPF:解决MaterialDesign:DialogHost 无法关闭问题
- [cocos creator] get the resource UUID
- Golang中删除字符串的最后一个字符
- Transplantation of freetype Library
- About the problem that the editor and the white screen of the login interface cannot be found after the location of unityhub is changed
- Conversion between JSON and object
猜你喜欢

What is a data type? What is the use of data types?

璞华PLM为全场景产品生命周期管理赋能,助力产品主线的企业数字化转型
![[step on the pit series] MySQL failed to modify the root password](/img/d0/f975baf18bac506208abff3713ac03.png)
[step on the pit series] MySQL failed to modify the root password

How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03

Unity change default editor

freetype库的移植

LwIP learning socket (application)

the installer has encountered an unexpected error installing this package

Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does

Unity XR realizes interaction (grasping, moving, rotating, transmitting, shooting) -pico
随机推荐
A tunnel to all ports of the server
Huawei s5700 switch initialization and configuration Telnet, SSH user methods
【cocos creator】获取资源uuid
【cocos creator】点击按钮切换界面
Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
一个实习生的CnosDB之旅
animation
idea取消引用显示效果
the installer has encountered an unexpected error installing this package
E: 无法定位软件包 ros-melodic-desktop-full
Pulitzer Prize in the field of information graphics - malofiej Award
LwIP learning socket (application)
Golang 中string和int类型相互转换
MAE
[untitled]
Three characteristics
Get to know unity2 for the first time
STM32F103 SPI (pit Diary)
YOLO系列 --- xml2txt脚本
Luaframwrok handles resource updates