Java tutorial
//package com.java2s; public class Main { public static int calculateLengthWithByte(String str) { int length = 0; for (int i = 0; i < str.length(); i++) { char tmp = str.charAt(i); if (tmp > 0 && tmp < 127) { length += 1; } else { length += 2; } } return length; } }