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); }
2.日期对应函数