remove HTML Tags from a string - Java java.lang

Java examples for java.lang:String HTML

Description

remove HTML Tags from a string

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String buffer = "java2s.com";
        System.out.println(removeHTMLTags(buffer));
    }/*from w  w w.  ja  va 2s  .  co  m*/

    public static String removeHTMLTags(String buffer) {
        StringBuilder result = new StringBuilder();
        boolean inHtmlTag = false;
        for (int x = 0; x < buffer.length(); x++) {
            if (buffer.charAt(x) == '<') {
                inHtmlTag = true;
            }
            if (!inHtmlTag) {
                result.append(buffer.charAt(x));
            }
            if (buffer.charAt(x) == '>') {
                inHtmlTag = false;
            }
        }
        return result.toString();
    }

    public static int length(String source) {
        int result = 0;
        if (isNotEmpty(source)) {
            result = source.length();
        }
        return result;
    }

    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }

    public static boolean isEmpty(String str) {
        return (str == null || str.length() == 0);
    }
}

Related Tutorials