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 7599445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:39:49+00:00 2026-05-30T22:39:49+00:00

I have a lab assignment and I’m dwelled on about removing html tags. Here

  • 0

I have a lab assignment and I’m dwelled on about removing html tags. Here is method for removing html tags:

public String getFilteredPageContents() {
    String str = getUnfilteredPageContents();
    String temp = "";
    boolean b = false;
    for(int i = 0; i<str.length(); i++) {
        if(str.charAt(i) == '&' || str.charAt(i) == '<') {
            b = true;
        }
        if(b == false) {
            temp += str.charAt(i);
        }
        if(str.charAt(i) == '>' || str.charAt(i) == ';') {
            b = false;
        }
    }
    return temp;
}

And here is my text’s earliest form:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage 2.0">
<title>A Shropshire Lad</title>
</head>

<body bgcolor="#008000" text="#FFFFFF" topmargin="10"
leftmargin="20">

<p align="center"><font size="6"><strong></strong></font>&nbsp;</p>
<div align="center"><center>

<pre><font size="7"><strong>A Shropshire Lad
</strong></font><strong>
by A.E. Housman
Published by Dover 1990</strong></pre>
</center></div>

<p><strong>This collection of sixty three poems appeared in 1896.
Many of them make references to Shrewsbury and Shropshire,
however, Housman was not a native of the county. The Shropshire
of his book is a mindscape in which he blends old ballad meters,
classical reminiscences and intense emotional experiences
&quot;recollected in tranquility.&quot; Although they are not
particularly to my taste, their style, simplicity and
timelessness are obvious even to me. Below are two short poems
which amused me, I hope you find them interesting too.</strong></p>

<hr size="8" width="80%" color="#FFFFFF">
<div align="left">

<pre><font size="5"><strong><u>
XIII</u></strong></font><font size="4"><strong>

When I was one-and-twenty
I heard a wise man say,
'Give crowns and pounds and guineas
But not your heart away;</strong></font></pre>
</div><div align="left">

<pre><font size="4"><strong>Give pearls away and rubies
But keep your fancy free.
But I was one-and-twenty,
No use to talk to me.</strong></font></pre>
</div><div align="left">

<pre><font size="4"><strong>When I was one-and-twenty
I heard him say again,
'The heart out of the bosom
Was never given in vain;
'Tis paid with sighs a plenty
And sold for endless rue'
And I am two-and-twenty,
And oh, 'tis true 'tis true.

</strong></font><strong></strong></pre>
</div>

<hr size="8" width="80%" color="#FFFFFF">

<pre><font size="5"><strong><u>LVI . The Day of Battle</u></strong></font><font
size="4"><strong>

'Far I hear the bugle blow
To call me where I would not go,
And the guns begin the song,
&quot;Soldier, fly or stay for long.&quot;</strong></font></pre>

<pre><font size="4"><strong>'Comrade, if to turn and fly
Made a soldier never die,
Fly I would, for who would not?
'Tis sure no pleasure to be shot.</strong></font></pre>

<pre><font size="4"><strong>'But since the man that runs away
Lives to die another day,
And cowards' funerals, when they come,
Are not wept so well at home,</strong></font></pre>

<pre><font size="4"><strong>'Therefore, though the best is bad,
Stand and do the best, my lad;
Stand and fight and see your slain,
And take the bullet in your brain.'</strong></font></pre>

<hr size="8" width="80%" color="#FFFFFF">
</body>
</html>

And when implement my method on this text:

 charset=iso-8859-1">

A Shropshire Lad







A Shropshire Lad

by A.E. Housman
Published by Dover 1990


This collection of sixty three poems appeared in 1896.
Many of them make references to Shrewsbury and Shropshire,
however, Housman was not a native of the county. The Shropshire
of his book is a mindscape in which he blends old ballad meters,
classical reminiscences and intense emotional experiences
recollected in tranquility. Although they are not
particularly to my taste, their style, simplicity and
timelessness are obvious even to me. Below are two short poems
which amused me, I hope you find them interesting too.
.
.
.

My question is: How can I get rid of that little code at the very beginning of text charset=iso-8859-1">. I can’t get away from that bunch of code? Thanks…

  • 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-05-30T22:39:50+00:00Added an answer on May 30, 2026 at 10:39 pm

    I can see that your intent is to remove stuff that looks like <xxx> and &xxx;. You’re using the variable b to remember whether you’re currently skipping stuff or not.

    Did you notice that your algorithm will skip things of the form <xxx; and &xxx>? Namely, & or < will cause skipping to begin, and > or ; will cause skipping to end, but you don’t have to match < with >, or & with ;. So how about implementing code to remember which character started the skip?

    A further complication, though, is that &xxx; stuff can be embedded in <xxx> stuff, like this: <p title="&amp;">

    Incidentally, temp += str.charAt(i); will make your program very slow when the string is long. Look at using StringBuilder instead.


    Here is some code that should solve your problem or nearly so:

    import java.util.Stack;
    
    public String getFilteredPageContents() {
        String str = getUnfilteredPageContents();
        StringBuilder() temp = new StringBuilder();
    
        // The closing character for each thing that we're inside
        Stack<Character> expectedClosing = new Stack<Character>();
    
        for(int i = 0; i<str.length(); i++) {
            char c = str.charAt(i);
            if(c == '<')
                expectedClosing.push('>');
            else if(c == '&')
                expectedClosing.push(';');
    
            // Is the current character going to close something?
            else if(!expectedClosing.empty() && c == expectedClosing.peek())
                expectedClosing.pop();
    
            else {
                // Only add to output if not currently inside something
                if(expectedClosing.empty())
                    temp.append(c);
            }
        }
        return temp.toString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an error when I call this method: public void updateEnrolled(String name, String
I have a question for a c++ lab assignment I have. The task is
I have a question regarding the online Google cloud lab @ http://code.google.com/apis/sql/docs/developers_guide_java.html at the
I am a student trying to finish a lab assignment. I have two files,
I have three button named(titled) hello, nothing, heaven and one label (IBOutlet UIlabel lab).
I have to use SQLPLUS for my database class, and our first assignment is
I am taking a hardware class than involves a lab, the lab is about
I have made this function to calculate color differences in the CIE Lab colorspace,
my robotics lab is looking for programmers to work on some projects we have
We're seeing an odd pattern in our QA Lab. We have two ASP.NET applications,

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.