Golang - ToUpper () in one byte?

I have []byte, band I want to select one byte, b[pos]and change it also in upper case (and then in lower case). The type byteshas a method called ToUpper(), How can I use this for one byte?

ToUpperSingle Byte Call

OneOfOne gave the most efficient (when called thousands of times), I use

val = byte(unicode.ToUpper(rune(b[pos])))

to find the byte and change the value

b[pos] = val

Check if byte is Upper

Sometimes, instead of changing the byte of a byte, I want to check if the byte is upper or lower case ; All bytes with an uppercase alphabet are lower than lowercase bytes.

func (b Board) isUpper(x int) bool {
    return b.board[x] < []byte{0x5a}[0]
}
+4
3

/ unicode.ToUpper.

b[pos] = byte(unicode.ToUpper(rune(b[pos])))
+7

, , ASCII:

func (b Board) isUpper(x int) bool {
    v := b.board[x]
    return 'A' <= v && v <= 'Z'
}

, :

func (b Board) isUpper(x int) bool {
    return b.board[x] <= 'Z'
}

:

  • , "Z" ( ).
  • "Z" 0x85 - , "Z".
  • "Z". .

: .

+2

OP, bytes.ToUpper() Unicode, UTF-8 , unicode.ToUpper() .

, OP , "b" , UTF-8, ASCII-7 8- , ISO Latin-1 (). OP ISO Latin-1 () ToUpper(), OP ISO Latin-1 () UTF-8 unicode bytes.ToUpper() unicode.ToUpper().

, , . ISO Latin-1 (,) .

+2
source

All Articles