当前位置:网站首页>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) //钱,孙,李
}
边栏推荐
- Wpf: solve the problem that materialdesign:dialoghost cannot be closed
- 链式长取值
- A tunnel to all ports of the server
- 创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
- [global product discovery 2] the first pure cloud augmented reality (AR) platform - Israel
- oracle 插入单引号
- Flex flexible box layout
- Luaframwrok handles resource updates
- An article for you to understand - Manchester code
- Multi traveling salesman problem -- overview of formula and solution process
猜你喜欢

数据的存储

C language learning notes (mind map)

An article for you to understand - Manchester code

vcs import src < ros2. Repos failed

How to configure GDAL under idea

Pulitzer Prize in the field of information graphics - malofiej Award

Transplantation of freetype Library

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

Multi traveling salesman problem -- overview of formula and solution process
![[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
随机推荐
oracle中的 (+)是什么意思
P2704 [noi2001] artillery position (shape pressure DP)
Editor Extensions
VMware virtual machine configuration static IP
regular expression
Basic operation and process control 2
2020-12-12
Demonstration of plug-in use of ventuz basic series
Worldview satellite remote sensing image data / meter resolution remote sensing image
[USACO12MAR]Cows in a Skyscraper G(状态压缩dp)
When did you find out that youth was over
Clip Related Script
Uniapp learning records
[at] ABC 258g - triple Reach - violence
【cocos creator】获取资源uuid
Yolo series --- xml2txt script
Technical dry goods | some thoughts on the future of AI architecture
[cocos creator] get the resource UUID
Getting started with minicom
多旅行商问题——公式和求解过程概述