Golang 如何将字符串转换为小写
在Go语言中,字符串与Java、C++、Python等其他语言不同。它是一个可变宽度字符序列,其中每个字符由一个或多个字节使用UTF-8编码表示。
在Go字符串中,您可以使用 ToLower() 函数将字符串转换为小写。此函数返回给定字符串的副本,其中所有Unicode字母都映射为小写。此函数定义在strings包中,因此您必须在程序中导入strings包才能访问此函数。
语法:
func ToLower(str string) string
在此,str表示要转换为小写的字符串。
示例:
输出:
Strings (before):
String 1: WelcomE, GeeksforGeeks**
String 2: This is the, tuTorial oF Golang##
String 3: HELLO! GOLANG
String 4: lowercase conversion
Strings (after):
Result 1: welcome, geeksforgeeks**
Result 2:this is the, tutorial of golang##
Result 3: hello! golang
Result 4: lowercase conversion