There is a code

textWithLinks = textWithLinks.replaceAll(name, "<a href=\""+name+".html\">"+name+"</a>"); System.out.println(textWithLinks); 

How should work:

 <a href="файл.html">файл</a> 

As a matter of fact:

 файл.html файл 

In short, the output gobbled up the tags, how to fix?

Help me please. thanks in advance

  • And you show that you have a name and that in textWithLinks .... most likely it just doesn’t find your name - Alexey Shimansky
  • @ Alexey Shimansky, with those in all normal, the tags simply are not displayed - user200192
  • If TAM is OK, but only the problems in the tags, then how to explain the normal behavior? ideone.com/HPTU50 - Alexey Shimansky
  • @ Alexey Shimansky, do you use the idea? - user200192
  • Yes. There are no problems - Alexey Shimansky

1 answer 1

I would not say that the problem is in html-tags, and the console normally displays a similar line, I don’t know, but the reason is probably in < and > , which are special characters and most likely the display problem with them, I won’t tell the reason, however I would still like to know it, so still try to replace these characters in this method with equivalents

< - &lt;

> - &gt;

Ie in the end you should be able to:

 .replaceAll(name, "&lt;a href=\""+name+".html\"&gt;"+name+"&lt;/a&gt;"); 


UPD: In general, the most likely reason is the use of methods for extracting text from html-code, since I have not encountered such problems in practice.

  • one
    Not. without special characters everything should be fine - Alexey Shimansky
  • Thanks a lot !) really works however I found other problems in the code - user200192