Java String Starts Wtih startswith(String s, String prefix)

Here you can find the source of startswith(String s, String prefix)

Description

This function performs a case-insensitive starts-with test.

License

Creative Commons License

Parameter

Parameter Description
s The string to examine
prefix The prefix to try

Return

True if the first string starts with the second, ignoring case.

Declaration

public static boolean startswith(String s, String prefix) 

Method Source Code

//package com.java2s;
/**// ww w  .  j a  v  a  2s . co m
 * Copyright (C) 2011 Darien Hager
 *
 * This code is part of the "HL2Parse" project, and is licensed under
 * a Creative Commons Attribution-ShareAlike 3.0 Unported License. For
 * either a summary of conditions or the full legal text, please visit:
 *
 * http://creativecommons.org/licenses/by-sa/3.0/
 *
 * Permissions beyond the scope of this license may be available
 * at http://technofovea.com/ .
 */

public class Main {
    /**
     * This function performs a case-insensitive starts-with test.
     * @param s The string to examine
     * @param prefix The prefix to try
     * @return True if the first string starts with the second, ignoring case.
     */
    public static boolean startswith(String s, String prefix) {
        if (s == null || prefix == null) {
            return false;
        }
        return s.toLowerCase().startsWith(prefix.toLowerCase());
    }
}

Related

  1. startsWith(String s, char c)
  2. startsWith(String s, int offset, int end, String t)
  3. startsWith(String s, String begin)
  4. startsWith(String s, String prefix)
  5. startsWith(String s, String prefix)
  6. startsWith(String s, String start)
  7. startsWith(String s, String start)
  8. startsWith(String s1, String s2)
  9. startsWith(String self, String pattern)