?
Solved

Convert text to HTML equivalent

Posted on 2005-03-21
5
Medium Priority
?
425 Views
Last Modified: 2010-08-05
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
Comment
Question by:lakshminair
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 15

Accepted Solution

by:
aozarov earned 100 total points
ID: 13598449
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
 

Author Comment

by:lakshminair
ID: 13598479
works great.

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

Assisted Solution

by:objects
objects earned 100 total points
ID: 13598636
> but isnt there any inbuilt java function which will handle the above

no there isn't

String.replaceAll() can be used.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 5 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question