go不使用工具包将大写字符转成小写字符的方法

时间:2024-05-31 08:05:49
package main

import (
"fmt"
) func main() {
str := "hellOWorlD" //返回str is all lower char
b := make([]byte, len(str))
for i, _:= range str{
s := str[i]
if 'A' <= s && s <= 'Z' {
s = s - 'A' + 'a'
}
b[i] = s
}
fmt.Println(str) //返回hellOWorlD
fmt.Printf("%s\n",b) //返回helloworld
}