althaf
spannableAmount = SpannableString(buildString { currency?.takeIf { it.isNotEmpty() }?.let { currency -> currencyLength1 = currency.length append("$currency") } amount?.takeIf { it.isNotEmpty() }?.let { amount -> amountLength1 = currencyLength1 + amount.length append(" $amount") } ratePercent?.takeIf { it.isNotEmpty() }?.let { rate -> rateLength1 = amountLength1 + rate.length append(" $ratePercent") } })
ildar.i [Android]
fun main() { val currency = "eur" val amount = "1000" val ratePercent = "10" var currencyLength1 = 0 var amountLength1 = 0 var rateLength1 = 0 val spannableAmount = buildString { currency?.takeIf { it.isNotEmpty() }?.let { currency -> currencyLength1 = currency.length append("$currency") } amount?.takeIf { it.isNotEmpty() }?.let { amount -> amountLength1 = currencyLength1 + amount.length append(" $amount") } ratePercent?.takeIf { it.isNotEmpty() }?.let { rate -> rateLength1 = amountLength1 + rate.length append(" $ratePercent") } } println(spannableAmount.toString()) println(rateLength1) }
Adrijan Rogan
if (currency != null && currency.isNotEmpty()) { currencyLength1 = currency.length append(currency) }
append(" $amount")
append(" ")
append(amount)
A modern programming language that makes developers happier.