Builder
Provides an API for building a NumberHexFormat.
This class is a builder for NumberHexFormat, and
serves as the type of the number
property when creating a new format using the HexFormat { }
builder
function. Each option in this class corresponds to an option in NumberHexFormat and defines it in the
resulting format. For example, use val format = HexFormat { number.removeLeadingZeros = true }
to set
NumberHexFormat.removeLeadingZeros. Refer to NumberHexFormat for details about how the configured
format options affect formatting and parsing results.
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val numberHexFormat = HexFormat {
upperCase = true
number {
removeLeadingZeros = true
minLength = 4
prefix = "0x"
}
}
println(0x3a.toHexString(numberHexFormat)) // 0x003A
println("0x003A".hexToInt(numberHexFormat)) // 58
// Parsing is case-insensitive
println("0X003a".hexToInt(numberHexFormat)) // 58
//sampleEnd
}
Properties
minLength
Defines NumberHexFormat.minLength of the format being built, 1
by default.
var minLength: Int
prefix
Defines NumberHexFormat.prefix of the format being built, empty string by default.
var prefix: String
removeLeadingZeros
Defines NumberHexFormat.removeLeadingZeros of the format being built, false
by default.
var removeLeadingZeros: Boolean
suffix
Defines NumberHexFormat.suffix of the format being built, empty string by default.
var suffix: String