当前位置:网站首页>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"))
}
边栏推荐
- Don't stop chasing the wind and the moon. Spring mountain is at the end of Pingwu
- Wang Zijian: is the NFT of Tencent magic core worth buying?
- 打通法律服务群众“最后一公里”,方正璞华劳动人事法律自助咨询服务平台频获“点赞”
- Lua 编程学习笔记
- XCiT学习笔记
- Improve the delivery efficiency of enterprise products (1) -- one click installation and upgrade of enterprise applications
- [hard core science popularization] working principle of dynamic loop monitoring system
- Exercise arrangement 2.10, 11
- Opencv learning notes II - basic image operations
- [kuangbin]专题十五 数位DP
猜你喜欢
Ebpf cilium practice (2) - underlying network observability
One click installation of highly available Nacos clusters in rainbow
[quick start of Digital IC Verification] 14. Basic syntax of SystemVerilog learning 1 (array, queue, structure, enumeration, string... Including practical exercises)
Open3D ISS关键点
Using nocalhost to develop microservice application on rainbow
一种适用于应用频繁测试下快速查看Pod的日志的方法(grep awk xargs kuberctl)
使用SwinUnet训练自己的数据集
Low success rate of unit test report
2-3查找樹
Analysis of maker education in innovative education system
随机推荐
Open3d ISS key points
2-3 lookup tree
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
在Rainbond中实现数据库结构自动化升级
Opencv learning notes II - basic image operations
下载和安装orcale database11.2.0.4
Implement your own dataset using bisenet
Analysis of maker education in innovative education system
[hard core science popularization] working principle of dynamic loop monitoring system
IP guard helps energy enterprises improve terminal anti disclosure measures to protect the security of confidential information
Domain specific language / DSL in kotlin
SSM 整合
机器人教育在动手实践中的真理
归并排序和非比较排序
Several ways of lambda used in functions in kotlin (higher-order functions)
GFS distributed file system
Coquette data completes the cloud native transformation through rainbow to realize offline continuous delivery to customers
One click installation of highly available Nacos clusters in rainbow
Opencv learning note 5 - gradient calculation / edge detection
A method for quickly viewing pod logs under frequent tests (grep awk xargs kuberctl)