I am trying to convert all HTML numbers
in a string.
I want to convert a String like "Let's find"
to "Let's find"
in Kotlin
i tested these but not worked:
str.toByteArray().toString(Charsets.UTF_8)
Kotlin convert String to InttoInt() to parse the string to an Int , NumberFormatException is thrown if the string is not a valid representation of an Integer. toIntOrNull() to convert the string to an Int , return a null if the string is not a valid representation of an Integer.
The simplest way to do this is to create an element, insert the string into with innerHTML , then return the element. /** * Convert a template string into HTML DOM nodes * @param {String} str The template string * @return {Node} The template HTML */ var stringToHTML = function (str) { var dom = document.
As suggested by second in the comments, you need to parse the html string using Html.fromHtml
and then get the string value from it.
var str:String = "Let's find"
str = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(str, Html.FROM_HTML_MODE_LEGACY).toString()
} else {
Html.fromHtml(str).toString()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With