6

I am trying to put a long dash "—" between two words in String in my Android project. For example something like this:

Name — Surname 

The String will be converted in code, not in xml. The only way i found to do this, is converting String to HTML and back. Like this:

stringBuilder.append(Name).append(" & mdash; ").append(Surname);  
Html.fromHtml(stringBuilder.toString()).toString();

(Space between "&" and "mdash;" to prevent convertation on stackoverflow).
Can it be done more elegant, without converting to HTML and back?
Thanks

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Eugene Dudnik
  • 63
  • 1
  • 5

1 Answers1

28

Have you tried unicode notation \u2014?

Reference: How to convert a string with Unicode encoding to a string of letters

Community
  • 1
  • 1
vokilam
  • 10,153
  • 3
  • 45
  • 56