Java examples for java.lang:String Length
get Real Length string length in GBK encoding
//package com.java2s; import java.io.UnsupportedEncodingException; public class Main { public static void main(String[] argv) { String str = "java2s.com"; System.out.println(getRealLength(str)); }/*from www . j a va 2 s.c o m*/ public static int getRealLength(String str) { try { return str.getBytes("GBK").length; } catch (UnsupportedEncodingException e) { return -1; } } }