当前位置:网站首页>字符串操作
字符串操作
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"))
}
边栏推荐
- Unityhub cracking & unity cracking
- Vulnerability recurrence fastjson deserialization
- Go语言中,函数是一种类型
- Rainbond 5.7.1 支持对接多家公有云和集群异常报警
- Opencv learning notes 1 -- several methods of reading images
- Automatic upgrading of database structure in rainbow
- CTF-WEB shrine模板注入nmap的基本使用
- 一文了解如何源码编译Rainbond基础组件
- Low success rate of unit test report
- Xcit learning notes
猜你喜欢

Implement your own dataset using bisenet

柯基数据通过Rainbond完成云原生改造,实现离线持续交付客户

轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷

Splunk查询csv lookup table数据动态查询

OpenVSCode云端IDE加入Rainbond一体化开发体系

Application of slip ring of shipborne radar antenna

Opencv learning notes 1 -- several methods of reading images
![[paper reading] icml2020: can autonomous vehicles identify, recover from, and adapt to distribution shifts?](/img/ff/81a7b2ec08a6a422a5cf578c1fed13.jpg)
[paper reading] icml2020: can autonomous vehicles identify, recover from, and adapt to distribution shifts?

Register of assembly language by Wang Shuang

Game attack and defense world reverse
随机推荐
漏洞複現-Fastjson 反序列化
Caractéristiques de bisenet
MES system is a necessary choice for enterprise production
BiSeNet的特點
一种适用于应用频繁测试下快速查看Pod的日志的方法(grep awk xargs kuberctl)
Interface as a parameter (interface callback)
Opencv learning notes 1 -- several methods of reading images
Coquette data completes the cloud native transformation through rainbow to realize offline continuous delivery to customers
Opencv learning note 3 - image smoothing / denoising
opencv学习笔记四——膨胀/腐蚀/开运算/闭运算
One click installation of highly available Nacos clusters in rainbow
Opencv learning note 4 - expansion / corrosion / open operation / close operation
buureservewp(2)
The use of generics and vararg variable parameters in kotlin
漏洞复现-easy_tornado
iptables 之 state模块(ftp服务练习)
Rainbond结合NeuVector实践容器安全管理
在Rainbond中实现数据库结构自动化升级
Analysis of maker education in innovative education system
Open3d ISS key points