Java String Starts Wtih startsWith(String s, String start)

Here you can find the source of startsWith(String s, String start)

Description

Returns true if, ignoring case, the string starts with the specified start string.

License

Open Source License

Parameter

Parameter Description
s the original string
start the string against which the beginning of string <code>s</code> are to be compared

Return

true if, ignoring case, the string starts with the specified start string; false otherwise

Declaration

public static boolean startsWith(String s, String start) 

Method Source Code

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

public class Main {
    /**//ww  w.j a  v  a  2 s.co  m
     * Returns <code>true</code> if, ignoring case, the string starts with the specified character.
     * 
     * @param s the string
     * @param begin the character against which the initial character of the string is to be compared
     * @return <code>true</code> if, ignoring case, the string starts with the specified character; <code>false</code> otherwise
     */
    public static boolean startsWith(String s, char begin) {
        return startsWith(s, (new Character(begin)).toString());
    }

    /**
     * Returns <code>true</code> if, ignoring case, the string starts with the specified start string.
     * 
     * @param s the original string
     * @param start the string against which the beginning of string <code>s</code> are to be compared
     * @return <code>true</code> if, ignoring case, the string starts with the specified start string; <code>false</code> otherwise
     */
    public static boolean startsWith(String s, String start) {
        if ((s == null) || (start == null)) {
            return false;
        }

        if (start.length() > s.length()) {
            return false;
        }

        String temp = s.substring(0, start.length());

        if (temp.equalsIgnoreCase(start)) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. startsWith(String s, String begin)
  2. startsWith(String s, String prefix)
  3. startsWith(String s, String prefix)
  4. startswith(String s, String prefix)
  5. startsWith(String s, String start)
  6. startsWith(String s1, String s2)
  7. startsWith(String self, String pattern)
  8. startsWith(String source, String target, boolean caseSensitive)
  9. startsWith(String str, char c)