Builder

Common
JVM
JS
Native
1.0
class Builder
(source)

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

Common
JVM
JS
Native
2.0

minLength

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

var minLength: Int
Common
JVM
JS
Native
1.0

prefix

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

var prefix: String
Common
JVM
JS
Native
1.0

removeLeadingZeros

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

var removeLeadingZeros: Boolean
Common
JVM
JS
Native
1.0

suffix

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

var suffix: String