0

I have a StringBuilder object in my class which I want to display on UI. This object has few html tags for ex: <li> <br> etc. I would like to know how to format this object so that the html tags are not shown as it is on screen, however they are converted to a readable format.

Note: I don't want to remove these tags and get a plain text. Rather if there is a <br> tag it should break line while displaying the text. Also, due to project restrictions I don't want to use any third party like jsoup etc.

Any help to achieve this would be appreciated!

schaturv
  • 122
  • 8

1 Answers1

0

How about simple .toString().replaceAll with specific replacements? Like:

<br> = \r\n

<li> = \r\n •

...and so on..

mi0
  • 166
  • 9
  • Yes that's one option but I have lot of tags and lot of strings so looking for some better solution. – schaturv May 26 '21 at 15:49
  • 1
    @schaturv If you cannot use suggested solution from Arvind (ie. use Browser component) and dont want to create your own parser, then take source code of existing parser (e.g. mentioned jsoup) and take parts/classes which you will need only. – mi0 May 26 '21 at 16:00