Search code examples
androidiosstringstringescapeutils

Line break (\n) not working in ios when escaped via StringEscapeUtils.escapeJava


I am using compile 'org.apache.commons:commons-lang3:3.4' library to convert emoji from my android app so that it can easily decoded in ios. So in my android app to encode string into unicode i am using this method StringEscapeUtils.escapeJava its working fine emoji sent via android app showing in ios but when i sent data which contains some line break, in ios it shows \n instead of showing text in new line.I tried

        val actualText=editText.text.toString()
        val oldText=StringEscapeUtils.escapeJava(actualText).toString()
        val newText=oldText.replace("\n", "\r\n")

but its not working.


Solution

  • After struggling a lot i found the issue. for these statements:

            val actualText=editText.text.toString()
            val oldText=StringEscapeUtils.escapeJava(actualText).toString()
            val newText=oldText.replace("\n", "\r\n")
    

    This picture(output) will clear everything

    enter image description here

    after using StringEscapeUtils.escapeJava for old text \n not considered as escape sequence character. So i changed replacement statement to:

    val reviewText=oldText.replace(StringEscapeUtils.escapeJava("\n"), "\r\n")
    

    and then output is:

    enter image description here

    after this in ios app instead of showing \n it shows text to the new line.