当前位置:网站首页>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"))
}
边栏推荐
- Use of out covariance and in inversion in kotlin
- Xcit learning notes
- Pytoch (VI) -- model tuning tricks
- Detailed explanation of apply, also, let, run functions and principle analysis of internal source code in kotlin
- Bisenet features
- DeiT学习笔记
- 下载和安装orcale database11.2.0.4
- [quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)
- Interface as a parameter (interface callback)
- [IELTS speaking] Anna's oral learning records Part3
猜你喜欢
OpenVSCode云端IDE加入Rainbond一体化开发体系
Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
DeiT学习笔记
Improve the delivery efficiency of enterprise products (1) -- one click installation and upgrade of enterprise applications
XCiT学习笔记
GFS分布式文件系统
Through the "last mile" of legal services for the masses, fangzheng Puhua labor and personnel law self-service consulting service platform has been frequently "praised"
Lua programming learning notes
Splunk query CSV lookup table data dynamic query
Virtual address space
随机推荐
一文了解如何源码编译Rainbond基础组件
POJ - 3784 Running Median(对顶堆)
Function extension, attribute extension and non empty type extension in kotlin
[untitled]
Lua programming learning notes
Splunk中single value视图使用将数值替换为文字
Data type - floating point (C language)
探索STEAM艺术设计中的创造力
Give full play to the wide practicality of maker education space
Practice of implementing cloud native Devops based on rainbow library app
How to realize the high temperature alarm of the machine room in the moving ring monitoring system
Installation and configuration of PLSQL
2 - 3 arbre de recherche
解读创客思维与数学课程的实际运用
Exercise arrangement 2.10, 11
Learn how to compile basic components of rainbow from the source code
Go语言中,函数是一种类型
Rainbond 5.6 版本发布,增加多种安装方式,优化拓扑图操作体验
基本数据类型和string类型互相转化
Rsync remote synchronization