這是我的第一個問題!
所以這是我的問題。
我有一個這樣的字串
var sentence string
string = "the biggest ocean is the Pacific ocean"
我希望能夠使tin 大寫,因此字串是
"The biggest ocean is the Pacific ocean"
感謝您的回復!
uj5u.com熱心網友回復:
獲取第一個符文,符文的標題大小寫并重新組合字串:
sentence := "the biggest ocean is the Pacific ocean"
r, i := utf8.DecodeRuneInString(sentence)
sentence = string(unicode.ToTitle(r)) sentence[i:]
fmt.Println(sentence)
uj5u.com熱心網友回復:
我為您提供了簡單的解決方案。
它是我在 Github 上某人專案的一個分支
https://github.com/CleanMachine1/capitalise
要使用它,只需在終端中運行:
go mod init MODULENAME
go get github.com/cleanmachine1/capitalise
然后在你的代碼中你可以使用
package main
import ("github.com/cleanmachine1/capitalise")
func main(){
sentence = capitalise.First(sentence)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/373121.html
標籤:走
上一篇:向Cobra包添加多個函式會導致[(novalue)usedasvalue]編譯錯誤
下一篇:通過反射創建結構實體并設定值
