英文:
How do I convert a string to a lower case representation?
问题
如何将字符串转换为小写形式?
我觉得肯定有内置的函数可以做到,但我就是找不到。
我在“unicode/letter”中找到了一个“ToLower”,但它只能逐个字符地工作。
英文:
How do I convert a string to a lower case representation?
I feel that there must be built-in function for it, but I just can't find it.
I did find a ToLower
in "unicode/letter"
, but it only works for one rune at a time.
答案1
得分: 172
是的,有的,可以查看字符串包。
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.ToLower("Gopher"))
}
英文:
Yes there is, check the strings package.
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.ToLower("Gopher"))
}
答案2
得分: 54
如果你懒得点击链接查看strings包,这里有示例代码:
strings.ToLower("Hello, WoRLd") // => "hello, world"
如果你需要处理阿塞拜疆语或土耳其语等Unicode特殊情况,你可以使用ToLowerSpecial
:
strings.ToLowerSpecial(unicode.TurkishCase, "Hello, WoRLd") // => "hello, world"
英文:
If you happen to be too lazy to click through to the strings package, here's example code:
strings.ToLower("Hello, WoRLd") // => "hello, world"
If you need to handle a Unicode Special Case like Azeri or Turkish, you can use ToLowerSpecial
:
strings.ToLowerSpecial(unicode.TurkishCase, "Hello, WoRLd") // => "hello, world"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论