4

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

Eugene
  • 59,186
  • 91
  • 226
  • 333

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
  • 132,198
  • 53
  • 198
  • 213
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,503
  • 4
  • 25
  • 36