Android String Sub String Get subStringByByte(String paramString, int beginIndex, int endIndex)

Here you can find the source of subStringByByte(String paramString, int beginIndex, int endIndex)

Description

sub String By Byte

Declaration

public static String subStringByByte(String paramString,
            int beginIndex, int endIndex) 

Method Source Code

//package com.java2s;

public class Main {
    public static String subStringByByte(String paramString,
            int beginIndex, int endIndex) {
        if ((paramString == null) || (paramString.length() == 0)) {
            return "";
        }/*from   w w  w.j  av a  2s  . c  om*/

        if (beginIndex >= endIndex) {
            return "";
        }

        int byteLength = 0;
        String returnString = "";
        for (int i = 0; i < paramString.length(); i++) {
            char c = paramString.charAt(i);
            byteLength += (0 <= c && c <= 255) ? 1 : 2;

            if (byteLength > endIndex) {
                break;
            }

            if (byteLength > beginIndex) {
                returnString += c;
            }
        }

        return returnString;
    }
}

Related

  1. deleteLast(String str, int num)
  2. deleteLastIf(String str, String eq_str)
  3. getTailorString(String string, int length)
  4. mid(String str, int beginIndex, int length)
  5. subStringByByte(String str, int startPos, int length)
  6. subString(String source, String start, int offsetStart, String end, int offsetEnd)
  7. subString(String str, int length)
  8. subInStringByFlag(String str, String flag)
  9. substringWithoutException(String text, int startIndex, int endIndex)