4

I need to substitute &nbps in TextView. I can simply use String.replace(), but there might be better solution?

Eugene
  • 57,641
  • 91
  • 219
  • 328

2 Answers2

3

try as using Pattern.compile:

Pattern p = Pattern.compile("&nbps");
String tempstr = "I love &nbps  &nbps.";

Matcher matcher = p.matcher(tempstr);
String tmp = matcher.replaceAll("Android");

you can see this post about performance of String.replace and matcher.replace

String replaceAll() vs. Matcher replaceAll() (Performance differences)

Community
  • 1
  • 1
ρяσѕρєя K
  • 130,641
  • 51
  • 193
  • 212
1

Try to use this function:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            mDescription.setText(Html.fromHtml("Your Text", Html.FROM_HTML_MODE_LEGACY));
        } else {
            mDescription.setText(Html.fromHtml("Your Text"));
        }
Mohamed AbdelraZek
  • 2,053
  • 3
  • 19
  • 32