【GO基礎】字符串

分割字符串

 strs := strings.Split("this is a string", " ")

截取字符串

str1 := "this is a string"
strs := str1[0:5]

拼接字符串

strs = strings.Join(strs,"_")

替換字符串

str := strings.Replace("this is a string", " ", "_", -1)

-1表示所有的空格都替換爲下劃線,如果是正數(n),就表示有n個空格替換爲下劃線

大小寫轉化

每個單詞首字母大寫

str := strings.toTitle("this is a string"

全部轉大寫

str := strings.toUpper("this is a string")

全部轉小寫

str := strings.toLower("THIS IS A STRING")
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章