Android HTML Tag Remove removeTags(String str)

Here you can find the source of removeTags(String str)

Description

remove Tags

Declaration

public static String removeTags(String str) 

Method Source Code

//package com.java2s;

public class Main {
    public static String removeTags(String str) {
        if (str == null) {
            throw new IllegalArgumentException("Str must not be null.");
        }/*from  w w  w  .j  a  v a2 s  .  com*/
        //
        StringBuffer out = new StringBuffer();
        char cs[] = str.toCharArray();
        boolean tagFound = false;
        int i1 = 0;
        int l = 0;
        //
        for (int i = 0; i < cs.length; i++) {
            if (cs[i] == '<' && !tagFound) {
                out.append(cs, i1, l);
                //
                i1 = i;
                l = 0;
                tagFound = true;
                l++;
            } else if (cs[i] == '>' && tagFound) {
                i1 = i + 1;
                l = 0;
                tagFound = false;
            } else {
                l++;
            }
        }
        if (l > 0) {
            out.append(cs, i1, l);
        }
        //
        return out.toString().trim();
    }
}

Related

  1. removeTags(final String source)
  2. removeTags(final String source, final String regex)