Java ASCII asciiIdx2StrIdx(String str, int asciiIdx)

Here you can find the source of asciiIdx2StrIdx(String str, int asciiIdx)

Description

ascii Idx Str Idx

License

Apache License

Declaration

public static int asciiIdx2StrIdx(String str, int asciiIdx) 

Method Source Code

//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;
    }
}

Related

  1. asciiEndsWithIgnoreCase(String source, String suffix)
  2. asciiEqualsIgnoreCase(byte[] a, byte[] b)
  3. asciiEqualsIgnoreCase(byte[] buf1, byte[] buf2)
  4. asciiFill2(String str, int startIdx, String fillStr)
  5. asciify(String s)
  6. asciiLength(String str)
  7. asciiPaddingR(String str, int length, String padding)
  8. asciiQuads(String word)
  9. asciiString(byte[] bytes, int from, int count)