Example usage for java.lang String regionMatches

List of usage examples for java.lang String regionMatches

Introduction

In this page you can find the example usage for java.lang String regionMatches.

Prototype

public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len) 

Source Link

Document

Tests if two string regions are equal.

Usage

From source file:Main.java

public static void main(String[] args) {

    String str1 = "tutorials from java2s.com";
    String str2 = "Java tutorials from java2s.com";

    str2 = "Consists of different Tutorials";
    boolean match1 = str1.regionMatches(true, 14, str2, 22, 10);
    System.out.println("region matched = " + match1);
}

From source file:Main.java

public static boolean startsWithIgnoreCase(final String string, final String prefix) {
    return string.regionMatches(true, 0, prefix, 0, prefix.length());
}

From source file:Main.java

public static boolean equalsIgnoreCase(String a, String b) {
    return (a == b) || (b != null) && (a.length() == b.length()) && a.regionMatches(true, 0, b, 0, b.length());
}

From source file:Main.java

/**
 * Helper functions to query a strings end portion. The comparison is case insensitive.
 *
 * @param base  the base string./*from  w  w  w .j  a va 2  s  .c  o  m*/
 * @param end  the ending text.
 *
 * @return true, if the string ends with the given ending text.
 */
public static boolean endsWithIgnoreCase(final String base, final String end) {
    if (base.length() < end.length()) {
        return false;
    }
    return base.regionMatches(true, base.length() - end.length(), end, 0, end.length());
}

From source file:Main.java

/**
 * Helper functions to query a strings start portion. The comparison is case insensitive.
 *
 * @param base  the base string.//from   w w w  .j  av  a  2s. c  o  m
 * @param start  the starting text.
 *
 * @return true, if the string starts with the given starting text.
 */
public static boolean startsWithIgnoreCase(final String base, final String start) {
    if (base.length() < start.length()) {
        return false;
    }
    return base.regionMatches(true, 0, start, 0, start.length());
}

From source file:Main.java

public static Collection<File> listFiles(File directory, String suffix) {
    final String _suffix = "." + suffix;
    FileFilter filter = new FileFilter() {
        @Override//from w  w  w.  j a v a  2s .  com
        public boolean accept(File file) {
            if (file.isDirectory())
                return true;
            String name = file.getName();
            int endLen = _suffix.length();
            if (name.regionMatches(true, name.length() - endLen, _suffix, 0, endLen)) {
                return true;
            }
            return false;
        }
    };
    if (!directory.isDirectory()) {
        throw new IllegalArgumentException("Parameter 'directory' is not a directory");
    }

    if (filter == null) {
        throw new NullPointerException("Parameter 'fileFilter' is null");
    }
    Collection<File> files = new LinkedList<File>();
    innerListFiles(files, directory, filter);
    return files;
}

From source file:com.avatarproject.core.command.APTabCompleter.java

/**
 * Breaks down the possible list and returns what is applicable depending on
 * what the user has currently typed./*from  ww  w.  ja v  a  2 s .c  om*/
 * 
 * @author D4rKDeagle
 * 
 * @param args Args of the command. Provide all of them.
 * @param possibilitiesOfCompletion List of things that can be given
 */
public static List<String> getPossibleCompletionsForGivenArgs(String[] args,
        List<String> possibilitiesOfCompletion) {
    String argumentToFindCompletionFor = args[args.length - 1];

    List<String> listOfPossibleCompletions = new ArrayList<String>();

    for (String foundString : possibilitiesOfCompletion) {
        if (foundString.regionMatches(true, 0, argumentToFindCompletionFor, 0,
                argumentToFindCompletionFor.length())) {
            listOfPossibleCompletions.add(foundString);
        }
    }
    Collections.sort(listOfPossibleCompletions);
    return listOfPossibleCompletions;
}

From source file:com.taobao.tdhs.jdbc.util.StringUtil.java

public static boolean startsWithIgnoreCase(String searchIn, int startAt, String searchFor) {
    return searchIn.regionMatches(true, startAt, searchFor, 0, searchFor.length());
}

From source file:org.apache.maven.artifact.ArtifactUtils.java

public static boolean isSnapshot(String version) {
    if (version != null) {
        if (version.regionMatches(true, version.length() - Artifact.SNAPSHOT_VERSION.length(),
                Artifact.SNAPSHOT_VERSION, 0, Artifact.SNAPSHOT_VERSION.length())) {
            return true;
        } else if (Artifact.VERSION_FILE_PATTERN.matcher(version).matches()) {
            return true;
        }/*from   w  w w. ja va2 s.  c om*/
    }
    return false;
}

From source file:Main.java

/**
 * Tests if specified string is a lexically correct target for a process
 * instruction./*from ww  w.  ja  va2 s  .  com*/
 * <p>
 * Note that Names starting with "<tt>xml</tt>" (case-insensitive) are
 * rejected.
 * 
 * @param s string to be tested
 * @return <code>true</code> if test is successful; <code>false</code>
 *         otherwise
 */
public static final boolean isPITarget(String s) {
    if (s == null || s.length() == 0)
        return false;
    return (isName(s) && !s.regionMatches(/* ignoreCase */true, 0, "xml", 0, 3));
}