Eugene
Eugene

Reputation: 60214

How to remove &nbsp from TextView

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

Upvotes: 4

Views: 2315

Answers (2)

Mohamed AbdelraZek
Mohamed AbdelraZek

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

ρяσѕρєя K
ρяσѕρєя K

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

Related Questions