当前位置:网站首页>String operation
String operation
2022-07-07 08:32:00 【Jimmy_ jimi】
package main
import (
"fmt"
"strconv"
"strings"
//"go/types"
)
func main() {
str := "hellow Elements "
// Statistical length
fmt.Println(len(str))
// String traversal
r := []rune(str)
for i:=0;i<len(r);i++{
fmt.Printf("%c ",r[i])
}
// String to integer
n,_ := strconv.Atoi("12")
fmt.Printf("\ntype:%T,date:%d",n,n)
// Integer to string
//%s character string ,%v Built in format content
//%v Output all values ,%+v Output field types and values ,%#V Output structure name and structure
m := strconv.Itoa(1234)
fmt.Printf("\ntype:%T,date:%v",m,m)
// String rotation []byte
//byte yes uint8 Another name for , It means only one byte ASCII code
println(" ")
var bytes = []byte("hellow go")
fmt.Printf("%v",bytes)
// Determine whether there is a string
fmt.Printf("\n Whether there is a string :%v",strings.Contains("safes","sa"))
// Count the number of strings
fmt.Printf("\n%v A string ",strings.Count("safeeeees","e"))
// Character to comparison
// "==" Case sensitive ,EqualFold Indistinguishes
fmt.Printf("\n%v",strings.EqualFold("abc","AbC"))
fmt.Println("abc"=="aBc")
// Returns the position of the first and last occurrence of a string , No return -1
fmt.Printf("%v",strings.Index("aaaaaa","a"))
fmt.Printf("\n%v",strings.LastIndex("aaaaaa","a"))
// Replace ,n Refers to the number of image replacements ,-1 For all
fmt.Printf("\n%v",strings.Replace("go to learn go","go","c Language ",-1))
// Split , The result is an array of characters
fmt.Printf("\n%v",strings.Split("go to learn go" ," "))
// Determine whether to start with a string / end
fmt.Printf("\n%v",strings.HasPrefix("sdqwe.log","s"))
fmt.Printf("\n%v",strings.HasSuffix("sdqwe.log","log"))
}
边栏推荐
- Open3d ISS key points
- Kotlin combines flatmap for filtering and zip merge operators
- 2-3 lookup tree
- [quick start of Digital IC Verification] 13. SystemVerilog interface and program learning
- Analysis of maker education in innovative education system
- Implement your own dataset using bisenet
- Rsync remote synchronization
- Open3D ISS关键点
- 【无标题】
- 【雅思口语】安娜口语学习记录 Part2
猜你喜欢

Golang 编译约束/条件编译 ( // +build <tags> )

GFS distributed file system

单场带货涨粉10万,农村主播竟将男装卖爆单?

Splunk中single value视图使用将数值替换为文字

Low success rate of unit test report

发挥创客教育空间的广泛实用性

MySQL introduction - crud Foundation (establishment of the prototype of the idea of adding, deleting, changing and searching)

Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?

DeiT学习笔记

Deit learning notes
随机推荐
How to realize the high temperature alarm of the machine room in the moving ring monitoring system
One click installation of highly available Nacos clusters in rainbow
GFS distributed file system
Openvscode cloud ide joins rainbow integrated development system
在Rainbond中实现数据库结构自动化升级
Splunk子查询模糊匹配csv中字段值为*
POJ - 3784 Running Median(对顶堆)
Train your dataset with swinunet
Snyk dependency security vulnerability scanning tool
SSM integration
Improve the delivery efficiency of enterprise products (1) -- one click installation and upgrade of enterprise applications
Pytoch (VI) -- model tuning tricks
Lua 编程学习笔记
IP guard helps energy enterprises improve terminal anti disclosure measures to protect the security of confidential information
eBPF Cilium实战(1) - 基于团队的网络隔离
Coquette data completes the cloud native transformation through rainbow to realize offline continuous delivery to customers
Through the "last mile" of legal services for the masses, fangzheng Puhua labor and personnel law self-service consulting service platform has been frequently "praised"
Data type - floating point (C language)
单元测试报告成功率低
Merge sort and non comparison sort