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

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
}

猜你喜欢

转载自www.cnblogs.com/wanghui-garcia/p/10568991.html