Java HTML to String htmlToStr(String htmlStr, int max_count)

Here you can find the source of htmlToStr(String htmlStr, int max_count)

Description

html To Str

License

Apache License

Declaration

public static String htmlToStr(String htmlStr, int max_count) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static String htmlToStr(String htmlStr, int max_count) {
        String result = "";
        boolean flag = true;
        if (htmlStr == null) {
            return null;
        }//from   w  w  w  .  j a v  a 2s  . c  o m
        char[] a = htmlStr.toCharArray();
        int length = a.length;
        for (int i = 0; i < length; i++) {
            if (a[i] == '<') {
                flag = false;
                continue;
            }
            if (a[i] == '>') {
                flag = true;
                continue;
            }
            if (flag == true) {
                result += a[i];
            }
        }
        if (result.toString().length() <= max_count * 1.1)
            return result.toString();
        return result.toString().substring(0, max_count) + "...";
    }
}

Related

  1. html2Plain(String text)
  2. html2Text(String html)
  3. htmlToString(String aS_Text)
  4. htmlToString(String s)
  5. htmlToString(String string)
  6. htmlToText(String html)