Reputation: 60214
I need to substitute &nbps
in TextView
. I can simply use String.replace()
, but there might be better solution?
Upvotes: 4
Views: 2315
Reputation: 2819
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"));
}
Upvotes: 1
Reputation: 132992
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)
Upvotes: 3