package main
/*golang字串的操作
*/import
("fmt"
s "strings"
)var
print
=fmt.println
func
main()
,"-"))
//重複乙個字串次數
print
("repeat"
, s.
repeat
("s",5
))//字串替換 指定起始位置為小於0,則全部替換 f00
print
("replace: "
, s.
replace
("foo"
,"o"
,"0",-
1))//字串替換 指定起始位置為1
print
("replace: "
, s.
replace
("folo"
,"o"
,"0",1
))//字串分割
print
("split"
, s.
split
("a-b-c-d-e"
,"-"))
//字串大小轉換 轉大寫
print
("upper"
, s.
toupper
("test"))
//字串大小寫轉化 轉小寫
print
("lower"
, s.
tolower
("test"))
//字串長度獲取
print
("len"
,len
("test"))
// 根據下表獲取字串中的字元,型別為byte
print
("char:"
,"hello"[1
])}
golang 字串操作例項
package main import s strings import fmt var p fmt.println func main 字串陣列 連線 a b p repeat s.repeat a 5 重複乙個字串 aaaaa p replace s.replace foo o 0 1 字串替換...
golang之字串操作
1.字串在另乙個字串第一次出現的位置 str hello world fmt.println strings.index str,world 62.字串在另乙個字串最後一次出現的位置 fmt.println strings.lastindex str,l 93.切割字串 fmt.println st...
Golang 字串型別和字串操作
package main import fmt func main 標準輸出 bo y 我來自 t中國package main import fmt func main 標準輸出 我叫boy false true true true false false truepackage main impo...