How to remove special character from string ”, ? etc

DWQA QuestionsCategory: android questionHow to remove special character from string ”, ? etc
kamal bunkar Staff asked 11 months ago

How to remove special character from string &#8221;, ? I am getting response from my wordpress website – I have follow this tutorial to get wordpress website into android app. Now I have response but it contains some special character like &#8221; #8217; <div> <a> etc. I want to remove it so it can be display on Recyclerview.


1 Answers
kamal bunkar Staff answered 11 months ago

The wordpress rest API response contains HTML tag which it good for view blog post on web browser but not good for android app. There is two way to doing this-

  1. You can remove special char from string by calling responsestring.replace(“special char here”, “”);
  2.  you can convert response into a string from htmlstring like that – 
    Html.fromHtml( response string here )

    But this method is depreciated on API 24 so you need to do it in a correct way-

    if (Build.VERSION.SDK_INT >= 24)
    post_description.setText(Html.fromHtml( response here , Html.FROM_HTML_MODE_LEGACY));
    post_description.setText(Html.fromHtml( response here ));