upper Case
Начиная с Kotlin: 2.2
var upperCase: Boolean
Задает HexFormat.upperCase формата, который создается, false по умолчанию.
См. HexFormat.upperCase, чтобы узнать, как этот параметр формата влияет на результат форматирования.
Примеры
import kotlin.test.*
fun main() {
//sampleStart
// By default, upperCase is set to false, so lower-case hexadecimal digits are used when formatting.
println(58.toHexString()) // 0000003a
println(58.toHexString(HexFormat.Default)) // 0000003a
// Setting upperCase to true changes the hexadecimal digits to upper-case.
println(58.toHexString(HexFormat { upperCase = true })) // 0000003A
println(58.toHexString(HexFormat.UpperCase)) // 0000003A
// The upperCase option affects only the case of hexadecimal digits.
val format = HexFormat {
upperCase = true
number.prefix = "0x"
}
println(58.toHexString(format)) // 0x0000003A
// The upperCase option also affects how byte arrays are formatted.
println(byteArrayOf(0x1b, 0xe6.toByte()).toHexString(format)) // 1BE6
// The upperCase option does not affect parsing; parsing is always case-insensitive.
println("0x0000003a".hexToInt(format)) // 58
println("\"1BE6\".hexToByteArray(format).contentEquals(byteArrayOf(0x1b, 0xe6.toByte())) is ${"1BE6".hexToByteArray(format).contentEquals(byteArrayOf(0x1b, 0xe6.toByte()))}") // true
//sampleEnd
}
© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.text/-hex-format/-builder/upper-case.html