0

I have an html text that has some html tags.

My Question :

How can I add that text into a label without those tags but keeping the text alignment?

For example :

if I have an "< /br>" as tag I need the same effect in the text added to the label but without the "< /br>" appearing in the text.

How can I make that?

Rene Pot
  • 24,681
  • 7
  • 68
  • 92
Manuel_Rodrigues
  • 560
  • 2
  • 18

2 Answers2

1

Couple solutions, if it is only about spacing (<br>) you could actually just replace the <br> with \n with regular expressions for example.

If it is more complicated (bold, italic, underlined, links) you can use Attributed Strings. If it is much more complicated than the supported types in Attributed strings you can use a webview, or StyledLabel.

Rene Pot
  • 24,681
  • 7
  • 68
  • 92
  • how can i replace the "/"? I'm trying this mister.replace(/
    /g, '/n'). but it does note work
    – Manuel_Rodrigues Jun 14 '16 at 10:14
  • you need to use `\n` not `/n` ;) – Rene Pot Jun 14 '16 at 10:23
  • Also, replace only does 1 instance, you need to replace all ;) – Rene Pot Jun 14 '16 at 10:24
  • The \N solved the enter problems but it keeps the / character. I'm doing it like this: var str = String(mStr).replace(/&/g, '').replace(//g, '').replace(/"/g, '').replace(/br/g, '\n'); – Manuel_Rodrigues Jun 14 '16 at 10:28
  • that is a terrible solution. Just go with replacing `
    ` and
    `. Don't go look for other elements like you do. And don't chain replaces: http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript
    – Rene Pot Jun 14 '16 at 10:44
-1

In Android you can apply

   Html.fromHtml("Html text")

i hope this could be help you.