当前位置:网站首页>字符串操作
字符串操作
2022-07-07 05:27:00 【Jimmy_jimi】
package main
import (
"fmt"
"strconv"
"strings"
//"go/types"
)
func main() {
str := "hellow元素"
//统计长度
fmt.Println(len(str))
//字符串遍历
r := []rune(str)
for i:=0;i<len(r);i++{
fmt.Printf("%c ",r[i])
}
//字符串转整数
n,_ := strconv.Atoi("12")
fmt.Printf("\ntype:%T,date:%d",n,n)
//整形转字符串
//%s 字符串,%v内置格式内容
//%v 输出所有值,%+v输出字段类型和值,%#V 输出结构体名字和结构体
m := strconv.Itoa(1234)
fmt.Printf("\ntype:%T,date:%v",m,m)
//字符串转[]byte
//byte 是uint8的别名,表示只占一个字节的ASCII码
println(" ")
var bytes = []byte("hellow go")
fmt.Printf("%v",bytes)
//判断是否存在字串
fmt.Printf("\n是否存在字串:%v",strings.Contains("safes","sa"))
//统计有几个字串
fmt.Printf("\n%v个字串",strings.Count("safeeeees","e"))
//字符转比较
// "=="区分大小写,EqualFold不区分
fmt.Printf("\n%v",strings.EqualFold("abc","AbC"))
fmt.Println("abc"=="aBc")
//返回字串第一次和最后一次出现的位置,没有返回-1
fmt.Printf("%v",strings.Index("aaaaaa","a"))
fmt.Printf("\n%v",strings.LastIndex("aaaaaa","a"))
//替换,n指像替换的数量,-1为全部
fmt.Printf("\n%v",strings.Replace("go to learn go","go","c 语言",-1))
//拆分,结果为字符转数组
fmt.Printf("\n%v",strings.Split("go to learn go" ," "))
//判断是否以字串开始/结束
fmt.Printf("\n%v",strings.HasPrefix("sdqwe.log","s"))
fmt.Printf("\n%v",strings.HasSuffix("sdqwe.log","log"))
}
边栏推荐
- [IELTS speaking] Anna's oral learning records Part3
- 轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
- Offer harvester: add and sum two long string numbers (classic interview algorithm question)
- 漏洞复现-easy_tornado
- PLSQL的安装和配置
- Use of out covariance and in inversion in kotlin
- [quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)
- Le système mes est un choix nécessaire pour la production de l'entreprise
- Splunk query CSV lookup table data dynamic query
- Opencv learning note 5 - gradient calculation / edge detection
猜你喜欢

Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster

Rsync remote synchronization

Using helm to install rainbow in various kubernetes

The largest 3 same digits in the string of leetcode simple question

Using nocalhost to develop microservice application on rainbow

Rainbow combines neuvector to practice container safety management
![[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)

Avatary's livedriver trial experience

Opencv learning note 5 - gradient calculation / edge detection

CCTV is so warm-hearted that it teaches you to write HR's favorite resume hand in hand
随机推荐
Understanding of out covariance, in inversion and invariance in kotlin
Avatary's livedriver trial experience
Rainbow combines neuvector to practice container safety management
Make LIVELINK's initial pose consistent with that of the mobile capture actor
解读创客思维与数学课程的实际运用
rsync远程同步
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
Interview questions (CAS)
归并排序和非比较排序
XCiT学习笔记
Tuowei information uses the cloud native landing practice of rainbow
Opencv learning note 5 - gradient calculation / edge detection
What is the function of paralleling a capacitor on the feedback resistance of the operational amplifier circuit
Pytoch (VI) -- model tuning tricks
Pvtv2--pyramid vision transformer V2 learning notes
Rainbond 5.7.1 支持对接多家公有云和集群异常报警
[quick start of Digital IC Verification] 13. SystemVerilog interface and program learning
拓维信息使用 Rainbond 的云原生落地实践
Analyzing the influence of robot science and technology development concept on Social Research
打通法律服务群众“最后一公里”,方正璞华劳动人事法律自助咨询服务平台频获“点赞”