prefix

Common
JVM
JS
Native
1.0
var prefix: String
(source)

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

The string must not contain line feed (LF) and carriage return (CR) characters.

Refer to NumberHexFormat.prefix for details about how this format option affects the formatting and parsing results.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
// By default, `prefix` is an empty string.
println(0x3a.toHexString()) // 0000003a
println("0000003a".hexToInt()) // 58

val prefixFormat = HexFormat { number.prefix = "0x" }

// `prefix` is placed before the hex representation.
println(0x3a.toHexString(prefixFormat)) // 0x0000003a
println("0x0000003a".hexToInt(prefixFormat)) // 58

// Parsing `prefix` is conducted in a case-insensitive manner.
println("0X0000003a".hexToInt(prefixFormat)) // 58

// Parsing fails if the input string does not start with the specified prefix.
// "0000003a".hexToInt(prefixFormat) // will fail with IllegalArgumentException
//sampleEnd
}

Exceptions

IllegalArgumentException - if a string containing LF or CR character is assigned to this property.