Java String Sub String substringByCodePoint(String inputStr, int codePointStart, int codePointEnd)

Here you can find the source of substringByCodePoint(String inputStr, int codePointStart, int codePointEnd)

Description

Returns a substring of the input string based on the input code points

License

Open Source License

Parameter

Parameter Description
inputStr a parameter
codePointStart a parameter
codePointEnd a parameter

Declaration

public static String substringByCodePoint(String inputStr, int codePointStart, int codePointEnd) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from w  ww.  ja va 2  s  .c  o m
     * Returns a substring of the input string based on the input code points
     * 
     * @param inputStr
     * @param codePointStart
     * @param codePointEnd
     * @return
     */
    public static String substringByCodePoint(String inputStr, int codePointStart, int codePointEnd) {
        int charOffsetStart = convertCodePointOffsetToCharOffset(inputStr, codePointStart);
        int charOffsetEnd = convertCodePointOffsetToCharOffset(inputStr, codePointEnd);
        return inputStr.substring(charOffsetStart, charOffsetEnd);
    }

    /**
     * Computes the character offset for the specified code point offset in the
     * input string
     * 
     * @param inputStr
     * @param codePointOffset
     * @return the character offset for the specified code point offset
     */
    public static int convertCodePointOffsetToCharOffset(String inputStr, int codePointOffset) {
        return inputStr.offsetByCodePoints(0, codePointOffset);
    }
}

Related

  1. substringBetweenStrings(String within, String pre, String post)
  2. subStringByByte(String orignal, int subcount)
  3. subStringByByte(String str, int byteLenth)
  4. substringByByteCount(String str, int byteCount)
  5. subStringByBytes(String str, int toCount, String more)
  6. substringByMask(String baseString, String baseMask, String subMask)
  7. subStringByte(String str, int toCount, String more)
  8. substringBytes(String value, int byte_len)
  9. substringCompare(String string, int index, char... characters)