Android examples for java.lang:String
Get string length by charset encoding
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main{ /**/* ww w .j av a2 s . c o m*/ * ?????????????. * * @param str * ?? * @param charset * ????GBK? * @return the int */ public static int strlen(String str, String charset) { if (str == null || str.length() == 0) { return 0; } int length = 0; try { length = str.getBytes(charset).length; } catch (Exception e) { e.printStackTrace(); } return length; } }