当前位置:网站首页>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"))
}
边栏推荐
- Golang 编译约束/条件编译 ( // +build <tags> )
- 打通法律服务群众“最后一公里”,方正璞华劳动人事法律自助咨询服务平台频获“点赞”
- PLSQL的安装和配置
- JS copy picture to clipboard read clipboard
- Implementation method of data platform landing
- 探索STEAM艺术设计中的创造力
- Implementation of navigation bar at the bottom of applet
- 利用 Helm 在各类 Kubernetes 中安装 Rainbond
- Domain specific language / DSL in kotlin
- Practice of implementing cloud native Devops based on rainbow library app
猜你喜欢
Installation and configuration of PLSQL
解析创新教育体系中的创客教育
2-3查找树
Application of slip ring of shipborne radar antenna
Battery and motor technology have received great attention, but electric control technology is rarely mentioned?
Iptables' state module (FTP service exercise)
Learn how to compile basic components of rainbow from the source code
iptables 之 state模块(ftp服务练习)
在 Rainbond 中一键安装高可用 Nacos 集群
[quick start of Digital IC Verification] 11. Introduction to Verilog testbench (VTB)
随机推荐
eBPF Cilium实战(1) - 基于团队的网络隔离
Ebpf cilium practice (2) - underlying network observability
Don't stop chasing the wind and the moon. Spring mountain is at the end of Pingwu
One click installation of highly available Nacos clusters in rainbow
Kotlin combines flatmap for filtering and zip merge operators
在Rainbond中一键部署高可用 EMQX 集群
IP-guard助力能源企业完善终端防泄密措施,保护机密资料安全
Implementation method of data platform landing
Open3d ISS key points
Famine cloud service management script
Coquette data completes the cloud native transformation through rainbow to realize offline continuous delivery to customers
Exercise arrangement 2.10, 11
BiSeNet的特點
Splunk子查询模糊匹配csv中字段值为*
Splunk查询csv lookup table数据动态查询
DeiT学习笔记
GOLand idea intellij 无法输入汉字
Splunk中single value视图使用将数值替换为文字
Rainbow combines neuvector to practice container safety management
MES system is a necessary choice for enterprise production