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.

Since Kotlin

1.9

Samples

import kotlin.test.*

fun main() { 
   //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

Link copied to clipboard

Defines NumberHexFormat.minLength of the format being built, 1 by default.

Since Kotlin 2.0
Link copied to clipboard

Defines NumberHexFormat.prefix of the format being built, empty string by default.

Since Kotlin 1.9
Link copied to clipboard

Defines NumberHexFormat.removeLeadingZeros of the format being built, false by default.

Since Kotlin 1.9
Link copied to clipboard

Defines NumberHexFormat.suffix of the format being built, empty string by default.

Since Kotlin 1.9