当前位置:网站首页>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) //钱,孙,李
}
边栏推荐
- tslib库的移植
- 【cocos creator】获取资源uuid
- Oracle queries grouped by time
- Register keyword
- Shader foundation 01
- What is a data type? What is the use of data types?
- Huawei switch: configure Telnet, SSH and web access
- E: 无法定位软件包 ros-melodic-desktop-full
- Use filechannel to copy files
- [end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
猜你喜欢

Worldview satellite remote sensing image data / meter resolution remote sensing image

Wechat applet taro learning record

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

How to establish rectangular coordinate system in space

Unity2019_ Lighting system

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

the installer has encountered an unexpected error installing this package

PostGIS space function

My touch screen production "brief history" 1

Oracle insert single quotation mark
随机推荐
Generate video using clipout in viz engine
Puhua PLM empowers the whole scene product lifecycle management and helps the enterprise digital transformation of the main line of products
C language - Introduction - essence Edition - take you into programming (I)
[at] ABC 258g - Triangle triples reachable - violence
Worldview satellite remote sensing image data / meter resolution remote sensing image
Basic operation and process control 2
C language learning notes (mind map)
[set theory] order relation (the relation between elements of partial order set | comparable | strictly less than | covering | Haas diagram)
Viz artist advanced script video tutorial -- stringmap use and vertex operation
Luaframwrok handles resource updates
E: Unable to locate package ROS melody desktop full
璞华PLM为全场景产品生命周期管理赋能,助力产品主线的企业数字化转型
Retail philosophy retail psychological warfare after reading -- 7-11 is a good product!
【cocos creator】获取资源uuid
freetype库的移植
JSON与Object之间转换
Maxcompute string splitting function -split_ PART
How to establish rectangular coordinate system in space
Unity one click AssetBundle
I want to do large screen data visualization application feature analysis