当前位置:网站首页>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
}
边栏推荐
- 一个实习生的CnosDB之旅
- Client server model
- 方正锐利重磅升级到12.0版本,包装印前处理更加便捷、高效!
- [set theory] order relation (the relation between elements of partial order set | comparable | strictly less than | covering | Haas diagram)
- 创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
- Base64编码简介
- MAE
- jupyter远程服务器配置以及服务器开机自启
- Get to know unity2 for the first time
- Wechat native applet cloud development learning record 01
猜你喜欢

How to configure GDAL under idea

STM32F103 SPI (pit Diary)

数据库应用技术课程设计之商城管理系统

Unity change default editor

Free use until 2015 -- viz artist multi touch plug-in package

多旅行商问题——公式和求解过程概述

vcs import src < ros2. Repos failed

L'installateur a été installé avec une erreur inattendue

【cocos creator】点击按钮切换界面

Editor Extensions
随机推荐
Dotween plug-in
Usage of (case, when) in PostgreSQL
Quality blog——
C#课程设计之员工信息管理系统
LinkList
Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
Mutual call between Lua and C #
Golang 时间格式整理
Ilruntime learning - start from scratch
C language - Introduction - essence Edition - take you into programming (I)
多旅行商问题——公式和求解过程概述
Demonstration of plug-in use of ventuz basic series
Install cross compiler arm none liunx gnueabihf
What does (+) in Oracle mean
Easy touch plug-in
方正锐利重磅升级到12.0版本,包装印前处理更加便捷、高效!
P1896 [SCOI2005] 互不侵犯(状压dp)
Pulitzer Prize in the field of information graphics - malofiej Award
[step on the pit series] MySQL failed to modify the root password
Lua framwrok framework starts