Java tutorial
//package com.java2s; public class Main { public static boolean allowMaxLenthOfString(String s, int charNum) { int num = 0; for (int i = 0; i < s.length(); i++) { String tmp = s.substring(i, i + 1); if (tmp.getBytes().length == 3) { num += 2; } else if (tmp.getBytes().length == 1) { num += 1; } } if (num <= charNum) { return true; } return false; } }