Hi, could someone help me convert this function in...
# android
z
Hi, could someone help me convert this function into kotlin? https://stackoverflow.com/a/23562910/3527128
d
Copy code
fun getText(context: Context, id: Int, args: Array<Any>): CharSequence {
    for (i in args.indices) {
        val value = args[i]
        if (value is String) {
            args[i] = TextUtils.htmlEncode(value)
        }
    }
    return Html.fromHtml(String.format(Html.toHtml(SpannedString(context.getText(id))), args))
}
p
Copy code
fun Context.getText(id: Int, vararg args: Any): CharSequence {
  val htmlEncodedArgs = args.map {
    if (it is String) {
      TextUtils.htmlEncode(it)
    } else {
      it
    }
  }
  return Html.fromHtml(String.format(Html.toHtml(SpannedString(getText(id))), *htmlEncodedArgs.toTypedArray()))
}