当前位置:网站首页>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
}
边栏推荐
- 多旅行商问题——公式和求解过程概述
- Unity XR realizes interaction (grasping, moving, rotating, transmitting, shooting) -pico
- STM32F103 SPI (pit Diary)
- JS to implement publish and subscribe
- Use filechannel to copy files
- animation
- About the problem that the editor and the white screen of the login interface cannot be found after the location of unityhub is changed
- 超限黑客认知
- String class
- Haproxy+kept build 01
猜你喜欢

Unity XR realizes interaction (grasping, moving, rotating, transmitting, shooting) -pico

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

Multi traveling salesman problem -- overview of formula and solution process

Get to know unity2 for the first time

Unity change default editor

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

My touch screen production "brief history" 1

unity2019_ Input management

Transplantation of freetype Library

What is a data type? What is the use of data types?
随机推荐
[end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
超限黑客认知
P1896 [scoi2005] non aggression (shape pressure DP)
Golang中删除字符串的最后一个字符
How to clear the console password for s7700 device
Install cross compiler arm none liunx gnueabihf
haproxy+keepalived集群搭建02
The difference between hdmi2.1 and hdmi2.0 and the conversion of PD signals.
P2622 关灯问题II(状态压缩 搜索)
Haproxy+kept build 01
How does yarn link help developers debug NPM packages?
Classes and objects
E: 无法定位软件包 ros-melodic-desktop-full
璞华PLM为全场景产品生命周期管理赋能,助力产品主线的企业数字化转型
JS to implement publish and subscribe
Mutual call between Lua and C #
Register keyword
[step on the pit series] MySQL failed to modify the root password
PIP uses image website to solve the problem of slow network speed
Ventuz Foundation Series "one step at the door"