go字符串常⽤⽅法总结1.常⽅法总结
package main
func main() {
//1.统计字符串长度
//str:="sdffsfdsf";
//fmt.Println(len(str));
//2.字符串变量同时出现中⽂的
//name:="你好⽔电费第三⽅是dsfs";
//slice:=[]rune(name);//使⽤rune切⽚转换为字节切⽚
//3.字符串转化为整数
//num:="12321";
/
/nums,_:=strconv.Atoi(num);
//fmt.Println(nums);
//4.整数转化为字符串返回值⼀个数字
//num:=12312;
//info:=strconv.Itoa(num);
//fmt.Println(info);
//5.字符串转化为字节切⽚因为是字节所以字节切⽚⾥⾯是整数
//str:="sdfdsfsd";
//str_slice := []byte(str);
//for _,val:=range str_slice{
//    fmt.Println(val);
/
/}
//6.字节切⽚转换为字符串
//nums:=string([]byte{97,98,99});
//fmt.Println(nums);
//7.查⼦传是否在⽗字符串⾥⾯返回true|false
//str_Children :="aa";
//str_Parent:="aabbcc";
//bol:=strings.Contains(str_Parent,str_Children);
//8.统计⼀个⼦字符串在⽗字符串⾥⾯出现的次数
//str:="e";
//strparent:="adfdsesdfsee";
/
/nums:=strings.Count(strparent,str);
//fmt.Println(nums);
//9.⽐较字符串不区分⼤⼩写
//str1:="ABC";
//str:="abc";
//bol:= strings.EqualFold(str1,str);
//fmt.Println(bol);
//10.返回⼦字符串第⼀次出现的位置index
//str:="abcefefd";
//target:="fd";
//num:=strings.Index(str,target);
/
/fmt.Println(num);
//11.字符串替换replace -1标识全部替换
//str:="abcedfdsfssfdooo";
//target:="ooo";
//replace:="<<<<";
//new_str:=strings.Replace(str,target,replace,-1);
//fmt.Println(new_str);
//12.字符串切割成字节切⽚
//str:="sdfjslkdfjdslkfjdslkfds";
//arr:=strings.Split(str,"");
//fmt.Println(arr);
/
/13.⼤⼩写转换
//str:="sdfsdfdss";
//target:=strings.ToUpper(str);//转换为⼤写
//fmt.Println(target);
//str:="DJFLKSJFLKDS";
//target:=strings.ToLower(str);//转为⼩写
//fmt.Println(target);
//14.去除左右两边空格
//str:="  ssdfdsfssf ";
//target_str:=strings.TrimSpace(str);
//fmt.Println(target_str);
/
/new_str:=" sdjfkls jfslkjsd fdsf ds !!";//去除制定空格    //info:=strings.Trim(new_str,"!");
//fmt.Println(info);
go语言字符串转数组}
2.⽇期对应函数

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。