当前位置:网站首页>字符串操作
字符串操作
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"))
}
边栏推荐
- opencv学习笔记四——膨胀/腐蚀/开运算/闭运算
- Opencv learning note 4 - expansion / corrosion / open operation / close operation
- Coquette data completes the cloud native transformation through rainbow to realize offline continuous delivery to customers
- MES系統,是企業生產的必要選擇
- Low success rate of unit test report
- Unityhub cracking & unity cracking
- CCTV is so warm-hearted that it teaches you to write HR's favorite resume hand in hand
- 探索STEAM艺术设计中的创造力
- 发挥创客教育空间的广泛实用性
- 接口作为参数(接口回调)
猜你喜欢
柯基数据通过Rainbond完成云原生改造,实现离线持续交付客户
Interactive book delivery - signed version of Oracle DBA work notes
The simple problem of leetcode is to judge whether the number count of a number is equal to the value of the number
发挥创客教育空间的广泛实用性
eBPF Cilium实战(1) - 基于团队的网络隔离
拓维信息使用 Rainbond 的云原生落地实践
一种适用于应用频繁测试下快速查看Pod的日志的方法(grep awk xargs kuberctl)
Train your dataset with swinunet
[untitled]
一文了解如何源码编译Rainbond基础组件
随机推荐
Open3d ISS key points
Go语言中,函数是一种类型
Transformation function map and flatmap in kotlin
[quick start of Digital IC Verification] 10. Verilog RTL design must know FIFO
Don't stop chasing the wind and the moon. Spring mountain is at the end of Pingwu
Several ways of lambda used in functions in kotlin (higher-order functions)
Splunk query CSV lookup table data dynamic query
MES系統,是企業生產的必要選擇
Bisenet features
buureservewp(2)
Le système mes est un choix nécessaire pour la production de l'entreprise
【雅思口语】安娜口语学习记录 Part3
Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms
opencv学习笔记一——读取图像的几种方法
Obsidan之数学公式的输入
Interface as a parameter (interface callback)
一种适用于应用频繁测试下快速查看Pod的日志的方法(grep awk xargs kuberctl)
Learn how to compile basic components of rainbow from the source code
JS copy picture to clipboard read clipboard
Implement your own dataset using bisenet