Java String Last Index Of lastIndexOfNewline(CharSequence theChars, int aStart)

Here you can find the source of lastIndexOfNewline(CharSequence theChars, int aStart)

Description

Returns index of the previous newline (or carriage-return/newline) in given chars starting at given char index.

License

Open Source License

Declaration

public static final int lastIndexOfNewline(CharSequence theChars, int aStart) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*  www.  j a v  a 2 s  .c  o  m*/
     * Returns index of the previous newline (or carriage-return/newline) in given chars starting at given char index. 
     */
    public static final int lastIndexOfNewline(CharSequence theChars, int aStart) {
        for (int i = aStart - 1; i >= 0; i--) {
            char c = theChars.charAt(i);
            if (c == '\n')
                return i - 1 >= 0 && theChars.charAt(i - 1) == '\r' ? (i - 1) : i;
            if (c == '\r')
                return i;
        }
        return -1;
    }
}

Related

  1. lastIndexOfIgnoreCase(String str, String searchStr)
  2. lastIndexOfIgnoreCase(String str, String searchStr)
  3. lastIndexOfIgnoreCase(String str, String searchStr, int startPos)
  4. lastIndexOfImpl(final String str, final String search, final int fromIndex, final boolean ignoreCase)
  5. lastIndexOfLetter(String string)
  6. lastIndexOfNonWhitespace(final String src)
  7. lastIndexOfOrdinal(String value, String part, int startIndex, int count, boolean caseSensitive)
  8. lastIndexOfPathSeparator(String str)
  9. lastIndexOfSeparator(String path)