Suppose you have the following string:
String s = \"The cold hand reaches for the %1$s %2$s Ellesse\'s\";
String old = \"old\";
String tan = \"tan\";
String fo
I made simple Kotlin extension function that should solve String.format
spanned issue:
fun Context.getStringSpanned(@StringRes resId: Int, vararg formatArgs: Any): Spanned {
var lastArgIndex = 0
val spannableStringBuilder = SpannableStringBuilder(getString(resId, *formatArgs))
for (arg in formatArgs) {
val argString = arg.toString()
lastArgIndex = spannableStringBuilder.indexOf(argString, lastArgIndex)
if (lastArgIndex != -1) {
(arg as? CharSequence)?.let {
spannableStringBuilder.replace(lastArgIndex, lastArgIndex + argString.length, it)
}
lastArgIndex += argString.length
}
}
return spannableStringBuilder
}