Flash AS2 how to detect HTML tags within text and remove

Posted on 2009-02-13
Last Modified: 2013-11-11

I'm wanting to create a function that can search through a string and find and remove any HTML tags.
I'm thinking along the line that if I search for the first < then search for the following > and count how many characters are in between, then remove them to create the new shorter string...

so  "this text has <br/> no <strong> tags" would end up as "this text has no tags";

Could anyone offer a solution on how to achieve this please.

Thanks in advance.


Question by:crooksy88
    LVL 37

    Accepted Solution

    I guess this is what you are looking for...

    You might also want to take a look at the Regular Expression...

    LVL 19

    Assisted Solution

    var start_tag_position:Number = 0;
    test_string = "This text has <br/> no <strong> tags";
    while (start_tag_position != -1) {
    start_tag_position = test_string.indexOf("<",0);
          if (start_tag_position != -1) {
                //alert - tag found now search for the closing tag
                end_tag_position = test_string.indexOf(">",0);
                      if (end_tag_position != -1) {
                      test_string = test_string.substring(0,start_tag_position) + test_string.substring(end_tag_position+1)
    LVL 13

    Author Closing Comment

    Thanks for your speedy responses.

    The solution Cyan Blue offered did the trick and I appreciate your input quizengine.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
    I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
    The goal of the tutorial is to teach the user how to how to record live broadcast.
    The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now