Here you can find the source of htmlSize(String str)
Parameter | Description |
---|---|
str | the string |
public static int htmlSize(String str)
//package com.java2s; //License from project: LGPL public class Main { /**/*from w w w .ja v a2s .c o m*/ * retreive the size of a String with html code. sample: "aaa´" = 4. * * @param str * the string * @return the size of the String; */ public static int htmlSize(String str) { int c = 0; int cInCode = 0; boolean inHTMLCode = false; for (int i = 0; i < str.length(); i++) { if (!inHTMLCode) { if (str.charAt(i) == '&') { inHTMLCode = true; cInCode++; } else { c++; } } else { cInCode++; if (str.charAt(i) == ';') { inHTMLCode = false; c++; cInCode = 0; } else if (str.charAt(i) == '&') { c = c + cInCode; cInCode = 0; } } } c = c + cInCode; return c; } }