Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8498895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:31:34+00:00 2026-06-11T00:31:34+00:00

I have a string from an RSS file after parsing. String htmlString= <p><img border=1

  • 0

I have a string from an RSS file after parsing.

String htmlString=

<p><img border="1" align="left" width="200" vspace="2" hspace="2" height="133" alt="Prime Minister Manmohan Singh will leave for Iran on August   28, 2012 to attend the Non-Aligned Movement summit, which will   be preceded by crucial bilateral talks with Iran&rsquo;s supreme   leader Ayotollah Ali Khamenei and Iranian President Mahmoud   Ahmadinejad." src="/tmdbuserfiles/manmohan ahmadi(3).jpg" />Prime Minister summit, which will be preceded by crucial bilateral talks with Iran&rsquo;s supreme leader place at a time when the U.S. is pushing India to reduce engagement with Iran and implement sanctions imposed by some countries over its controversial nuclear programme.<br />
    <br />
    &nbsp;</p>

I have a requirement to display the text without any HTML tags and without HTML special characters from above htmlString on my LWUIT Form like:

Prime Minister ManmohanSingh will leave for Iran on August 28, 2012 to attend the Non-Aligned Movement summit, which will  
be preceded by crucial bilateral talks with Iran supreme leader Ayotollah Ali Khamenei and Iranian etc...........?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:31:36+00:00Added an answer on June 11, 2026 at 12:31 am

    It also helps to open the HttpConnection input stream with UTF-8 encoding like this :

    String encoding = "UTF-8";
    Reader reader = new InputStreamReader(in, encoding);
    

    Use this suite of String Utils to get clean and well formatted text. :

     /**
     * Method removes HTML tags from given string.
     *
     * @param text  Input parameter containing HTML tags (eg. <b>cat</b>)
     * @return      String without HTML tags (eg. cat)
     */
    public static String removeHtml(String text) {
        try {
            int idx = text.indexOf("<");
            if (idx == -1) {
                text = decodeEntities(text);
                return text;
            }
    
            String plainText = "";
            String htmlText = text;
            int htmlStartIndex = htmlText.indexOf("<", 0);
            if (htmlStartIndex == -1) {
                return text;
            }
            htmlText = StringUtils.replace(htmlText, "</p>", "\r\n");
            htmlText = StringUtils.replace(htmlText, "<br/>", "\r\n");
            htmlText = StringUtils.replace(htmlText, "<br>", "\r\n");
            while (htmlStartIndex >= 0) {
                plainText += htmlText.substring(0, htmlStartIndex);
                int htmlEndIndex = htmlText.indexOf(">", htmlStartIndex);
                htmlText = htmlText.substring(htmlEndIndex + 1);
                htmlStartIndex = htmlText.indexOf("<", 0);
            }
            plainText = plainText.trim();
            plainText = decodeEntities(plainText);
            return plainText;
        } catch (Exception e) {
            System.err.println("Error while removing HTML: " + e.toString());
            return text;
        }
    }
    
    public static String decodeEntities(String html) {
        String result = StringUtils.replace(html, "&lt;", "<");
        result = StringUtils.replace(result, "&gt;", ">");
        result = StringUtils.replace(result, "&nbsp;", " ");
        result = StringUtils.replace(result, "&amp;", "&");
        result = StringUtils.replace(result, "&auml;", "ä");
        result = StringUtils.replace(result, "&ouml;", "ö");
        result = StringUtils.replace(result, "&quot;", "'");
        result = StringUtils.replace(result, "&lquot;", "'");
        result = StringUtils.replace(result, "&rquot;", "'");
        result = StringUtils.replace(result, "&#xd;", "\r");
        return result;
    }
    
    /* Replace all instances of a String in a String.
     *   @param  s  String to alter.
     *   @param  f  String to look for.
     *   @param  r  String to replace it with, or null to just remove it.
     */
    public static String replace(String s, String f, String r) {
        if (s == null) {
            return s;
        }
        if (f == null) {
            return s;
        }
        if (r == null) {
            r = "";
        }
        int index01 = s.indexOf(f);
        while (index01 != -1) {
            s = s.substring(0, index01) + r + s.substring(index01 + f.length());
            index01 += r.length();
            index01 = s.indexOf(f, index01);
        }
        return s;
    }
    
    public static String cleanEncodedString(String str) {
        String resultStr = str;
        String encoding = "UTF-8";
    
        InputStream in = new ByteArrayInputStream(str.getBytes());
        InputStreamReader isr;
        try {
            isr = new InputStreamReader(in, encoding);
    
            ByteArrayOutputStream buf = new ByteArrayOutputStream();
            int result = isr.read();
            while (result != -1) {
                byte b = (byte) result;
                buf.write(b);
                result = isr.read();
            }
            resultStr = buf.toString();
    
            return resultStr;
        } catch (Exception uee) {
            uee.printStackTrace();
        }
        return resultStr;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI, I have some string from XML file, and I I want to replace
I have a formatted string from a log file, which looks like: >>> a=test
I have an XML file taken from an RSS feed, saved locally, and I
I have a program where I take a date from an RSS file and
I have a string I have parsed from a RSS feed thumbnail url='http://photos3.media.pix.ie/11/C5/11C5B77C92204ADBBD0CF5FDF4BA351B-0000314357- 0002211156-00240L-00000000000000000000000000000000.jpg'
I have a string input from which I need to extract simple information, here
I have below string String str=select * from m_menus; select * from m_roles; I
I have a string built from a few segments, which are not separated, but
I have a string read from another source such as \b\bfoo\bx. In this case,
I have a string value from a user input box. I have to figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.