当前位置:网站首页>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"))
}
边栏推荐
- iptables 之 state模块(ftp服务练习)
- 提高企业产品交付效率系列(1)—— 企业应用一键安装和升级
- Understanding of out covariance, in inversion and invariance in kotlin
- Pvtv2--pyramid vision transformer V2 learning notes
- AVL平衡二叉搜索树
- Domain specific language / DSL in kotlin
- 基本数据类型和string类型互相转化
- 饥荒云服管理脚本
- OpenVSCode云端IDE加入Rainbond一体化开发体系
- Splunk中single value视图使用将数值替换为文字
猜你喜欢

Explore creativity in steam art design

The field value in Splunk subquery fuzzy matching CSV is*

Automatic upgrading of database structure in rainbow

Deit learning notes
![[quick start of Digital IC Verification] 14. Basic syntax of SystemVerilog learning 1 (array, queue, structure, enumeration, string... Including practical exercises)](/img/60/011b3ccdffa978d691436449a99e10.png)
[quick start of Digital IC Verification] 14. Basic syntax of SystemVerilog learning 1 (array, queue, structure, enumeration, string... Including practical exercises)

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

iptables 之 state模块(ftp服务练习)

Opencv learning notes 1 -- several methods of reading images

Lua programming learning notes

单场带货涨粉10万,农村主播竟将男装卖爆单?
随机推荐
发挥创客教育空间的广泛实用性
Function extension, attribute extension and non empty type extension in kotlin
在 Rainbond 中一键安装高可用 Nacos 集群
Learn how to compile basic components of rainbow from the source code
在Rainbond中实现数据库结构自动化升级
Ebpf cilium practice (2) - underlying network observability
The truth of robot education in hands-on practice
Deit learning notes
IP guard helps energy enterprises improve terminal anti disclosure measures to protect the security of confidential information
[IELTS speaking] Anna's oral learning records Part3
Le système mes est un choix nécessaire pour la production de l'entreprise
Analysis of maker education in innovative education system
2-3 lookup tree
Pvtv2--pyramid vision transformer V2 learning notes
机器人教育在动手实践中的真理
Domain specific language / DSL in kotlin
Ebpf cilium practice (1) - team based network isolation
opencv学习笔记五——梯度计算/边缘检测
使用BiSeNet实现自己的数据集
eBPF Cilium实战(2) - 底层网络可观测性