Java String Sub String substring(final String string, int fromIndex, int toIndex)

Here you can find the source of substring(final String string, int fromIndex, int toIndex)

Description

substring

License

Open Source License

Declaration

public static String substring(final String string, int fromIndex, int toIndex) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String substring(final String string, int fromIndex, int toIndex) {
        final int len = string.length();
        if (fromIndex < 0) {
            fromIndex += len;/*  w  w  w. j  a v a  2 s. c  om*/
            if (toIndex == 0) {
                toIndex = len;
            }
        }
        if (toIndex < 0) {
            toIndex += len;
        }
        if (fromIndex < 0) {
            fromIndex = 0;
        }
        if (toIndex > len) {
            toIndex = len;
        }
        if (fromIndex >= toIndex) {
            return "";
        }
        return string.substring(fromIndex, toIndex);
    }
}

Related

  1. substring(final String pSource, final String pBeginBoundaryString, final String pEndBoundaryString, final int pOffset)
  2. substring(final String s, int start)
  3. substring(final String s, int start, int end)
  4. substring(final String s, int startIndex, int endIndex)
  5. substring(final String str, int start, int end)
  6. substring(final String text, final int position, final int length)
  7. substring(String _text, int _idx)
  8. substring(String baseString, int start, int end)
  9. subString(String input, char start, char end)