当前位置:网站首页>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
- 2020-12-12
- Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
- JS common basic case sorting (continuous update)
- The difference between hdmi2.1 and hdmi2.0 and the conversion of PD signals.
- Install cross compiler arm none liunx gnueabihf
- 十六进制编码简介
- Viz artist advanced script video tutorial -- stringmap use and vertex operation
- Idea dereference display effect
- I want to do large screen data visualization application feature analysis
猜你喜欢

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

Dotween plug-in

A tunnel to all ports of the server

Unity2019_ Natural ambient light_ Sky box
![[untitled]](/img/3d/27a7229e3f0ccf0ca5ae1f00a92513.jpg)
[untitled]

the installer has encountered an unexpected error installing this package

animation

Haproxy+kept build 01

Shader foundation 01

Open the influence list of "National Meteorological Short Videos (Kwai, Tiktok) in November" in an interactive way“
随机推荐
Idea dereference display effect
Shader foundation 01
CLion-Toolchains are not configured Configure Disable profile问题解决
Getting started with minicom
MaxCompute字符串分割函数-SPLIT_PART
haproxy+keepalived搭建01
链式长取值
Transplantation of tslib Library
璞华PLM为全场景产品生命周期管理赋能,助力产品主线的企业数字化转型
Free use until 2015 -- viz artist multi touch plug-in package
unity2019_ Input management
I want to do large screen data visualization application feature analysis
C语言-入门-精华版-带你走进编程(一)
Worldview satellite remote sensing image data / meter resolution remote sensing image
数据库应用技术课程设计之商城管理系统
MXone Pro自适应2.0影视模板西瓜视频主题苹果cmsV10模板
Xlua task list youyou
JS common basic case sorting (continuous update)
tslib库的移植
Basic operation and process control