Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin : how to Convert String with HTML numbers to String without HTML numbers

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)

like image 515
mhKarami Avatar asked Jul 25 '19 05:07

mhKarami


People also ask

How do I convert a string to a number in Kotlin?

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.

How do you convert a string in HTML?

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.


1 Answers

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() 
        }
like image 94
Chrisvin Jem Avatar answered Oct 19 '22 03:10

Chrisvin Jem