Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 438
  • Last Modified:

Convert text to HTML equivalent

Hi All,

I have string

x="<paper jam>"

Now i want the html equivalent as &lt;paper+&gt;

is there some java function which can do this.

Regards,
Lakshmi
0
lakshminair
Asked:
lakshminair
2 Solutions
 
aozarovCommented:
String escapeXMLTags(String value)
   {
      int length = value.length();
      StringBuffer stBuff = new StringBuffer(length);
     
      for(int i = 0; i < length ; i++)
      {
         char ch = value.charAt(i);
         
       switch (ch)
         {  
            case '<':
               stBuff.append("&lt;");
               break;
            case '>':
               stBuff.append("&gt;");
               break;
            case '&':
               stBuff.append("&amp;");
               break;
            case '\"':
               stBuff.append("&quot;");
               break;
            case '\'':
               stBuff.append("&#x27;");
               break;
            default:
               stBuff.append(ch);
               break;
         }
      }
     
      return stBuff.toString();
   }
0
 
lakshminairAuthor Commented:
works great.

but isnt there any inbuilt java function which will handle the above. like a pre-defined class
0
 
objectsCommented:
> but isnt there any inbuilt java function which will handle the above

no there isn't

String.replaceAll() can be used.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now