Java String Sub String substring2ByteString(String str, int endIndex)

Here you can find the source of substring2ByteString(String str, int endIndex)

Description

substring Byte String

License

Open Source License

Declaration

private static String substring2ByteString(String str, int endIndex) 

Method Source Code

//package com.java2s;

public class Main {
    private static String substring2ByteString(String str, int endIndex) {
        if (str == null) {
            return null;
        }/*from   www .  ja v  a 2s.c om*/

        byte[] strByte = str.getBytes();
        int i, strLen;

        strLen = strByte.length;

        if (strLen <= endIndex) {
            return str;
        }

        int cnt = 0;
        for (i = 0; i < endIndex; i++) {
            if ((((int) strByte[i]) & 0xff) > 0x80) {
                cnt++;
            }
        }
        if ((cnt % 2) == 1) {
            i--;
        }

        return new String(strByte, 0, i);
    }
}

Related

  1. substring(String text, int startPos, int len)
  2. subString(String text, String leadingPart)
  3. subString(String val, int start, int end)
  4. SubString(String x, long y)
  5. substring(StringBuffer buf, int start, int lim)
  6. subString4lastIndex(String string, String regex)
  7. substringAfter(final String str, final String separator)
  8. substringAfter(String s, String cs)
  9. substringAfter(String s, String substr, boolean fromend)