Here you can find the source of asciiIdx2StrIdx(String str, int asciiIdx)
public static int asciiIdx2StrIdx(String str, int asciiIdx)
//package com.java2s; //License from project: Apache License public class Main { public static int asciiIdx2StrIdx(String str, int asciiIdx) { int length = 0; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); length += c > 127 ? 2 : 1; if (length >= asciiIdx) return i; }/*from www . jav a 2 s . co m*/ return -1; } }