当前位置:网站首页>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) //钱,孙,李
}
边栏推荐
- [end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
- YOLO系列 --- xml2txt脚本
- STM32F103 SPI (pit Diary)
- Usage of (case, when) in PostgreSQL
- My touch screen production "brief history" 1
- Idea unreference Display Effect
- 链式长取值
- MAE
- WPF:解决MaterialDesign:DialogHost 无法关闭问题
- Yolo series --- xml2txt script
猜你喜欢

IP production stream is so close to me

数据的存储

Technical dry goods | Bert model for the migration of mindspore NLP model - text matching task (2): training and evaluation

Ventuz Foundation Series "one step at the door"

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

方正锐利重磅升级到12.0版本,包装印前处理更加便捷、高效!

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

CLion-Toolchains are not configured Configure Disable profile问题解决

An intern's journey to cnosdb

【cocos creator】点击按钮切换界面
随机推荐
Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task
Idea dereference display effect
Static keyword
Youyou1 of xlua knapsack system
一个实习生的CnosDB之旅
Quelle est la définition? Qu'est - ce qu'une déclaration? Quelle est la différence?
Technical dry goods | Bert model for the migration of mindspore NLP model - text matching task (2): training and evaluation
Unity XR realizes interaction (grasping, moving, rotating, transmitting, shooting) -pico
什么是数据类型?数据类型有什么用?
Transplantation of freetype Library
P1896 [SCOI2005] 互不侵犯(状压dp)
多旅行商问题——公式和求解过程概述
I want to do large screen data visualization application feature analysis
[end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
[USACO12MAR]Cows in a Skyscraper G(状态压缩dp)
Ventuz Foundation Series "one step at the door"
Iterm2 setting
Unity change default editor
WPF:解决MaterialDesign:DialogHost 无法关闭问题
Getting started with minicom