prefix
Начиная с Kotlin: 2.2
var prefix: String
Задаёт NumberHexFormat.prefix создаваемого формата; по умолчанию используется пустая строка.
Строка не должна содержать символы перевода строки (LF) и возврата каретки (CR).
Подробнее о том, как этот параметр формата влияет на результаты форматирования и разбора, см. в описании NumberHexFormat.prefix.
Исключения
если этому свойству присвоена строка, содержащая символ LF или CR.
Примеры
import kotlin.test.*
fun main() {
//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
}
© 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/-number-hex-format/-builder/prefix.html