將帶空格的字串轉換為單個駝峰式字串的最簡單方法是什么?
例如:“這是一個帶空格的字串”->“thisIsAStringWithSpaces”
uj5u.com熱心網友回復:
如果只處理空格,可以避免使用正則運算式。有關strings可用于擴展此功能的有用幫助程式,請參閱包:
str := "This is a string with spaces"
words := strings.Split(str, " ")
key := strings.ToLower(words[0])
for _, word := range words[1:] {
key = strings.Title(word)
}
log.Println(key)
uj5u.com熱心網友回復:
就個人而言,我喜歡使用這個庫 https://github.com/iancoleman/strcase
strcase.ToLowerCamel("This is a string with spaces")
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/364096.html
標籤:走
下一篇:Kafka登錄go服務
