Home > front end >  Escaped characters are not working with dynamic strings in Kotlin
Escaped characters are not working with dynamic strings in Kotlin

Time:02-01

I'm trying to set dynamic strings into textView which have escaped characters. But those strings are always getting printed as same string. \n, \r etc. are not performing their operations like next line.

  val str: String = "Jam\nes"
  textView.text = str

I have tried using as HTML string also but that also din't work.

  val str: String = "Jam\nes"
  val spanned = HtmlCompat.fromHtml(str, HtmlCompat.FROM_HTML_MODE_LEGACY)
  textView.text = spanned

Output: Jam\nes

Expected result:

Jam

es

CodePudding user response:

\n has to work on textView with string. You can check textView android:lines="1" in XML.

Also \n is not supported for HtmlCompat. You can use <br> or <br/>

CodePudding user response:

try

"jam${System.getProperty("line.separator")}nes"
  •  Tags:  
  • Related