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
}

 

posted @ 2019-03-20 23:53  慢行厚积  阅读(667)  评论(0编辑  收藏  举报