Example usage for org.apache.commons.lang StringUtils countMatches

List of usage examples for org.apache.commons.lang StringUtils countMatches

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils countMatches.

Prototype

public static int countMatches(String str, String sub) 

Source Link

Document

Counts how many times the substring appears in the larger String.

Usage

From source file:StringUtilsExampleV1.java

public static void main(String args[]) {

    System.err.println(StringUtils.countMatches("arthur", "r"));
}

From source file:Main.java

public static void main(String[] args) {
    String source = "this is a test";
    String word = "is";

    int wordFound = StringUtils.countMatches(source, word);

    System.out.println(wordFound);
}

From source file:net.binout.asciidoc.AsciidocReader.java

public static void main(String[] args) {
    Asciidoctor asciidoctor = Asciidoctor.Factory.create();

    // Read the document header : title for example
    DocumentHeader documentHeader = asciidoctor.readDocumentHeader(getJugSummerCampDoc());
    System.out.println(documentHeader.getDocumentTitle().getMain());

    // Read the document structure
    StructuredDocument document = asciidoctor.readDocumentStructure(getJugSummerCampDoc(),
            Collections.<String, Object>emptyMap());

    // Find the part with title "Speakers"
    ContentPart speakers = document.getParts().stream().filter(p -> "Speakers".equals(p.getTitle())).findFirst()
            .get();//from w  w w  .  j  a v a2s.c  o m
    // Count the number of speakers
    System.out.println(StringUtils.countMatches(speakers.getContent(), "sect2") + " speakers");
}

From source file:com.rslakra.java.string.TestApacheStringUtils.java

public static void main(String args[]) {

    System.err.println(StringUtils.abbreviate("Take time off working", 0, 10));
    System.err.println(StringUtils.capitalize("vanderLust"));
    System.err.println(StringUtils.center("MTV", 7, '='));
    System.err.println(StringUtils.chomp("temperature", "ure"));
    System.err.println(StringUtils.chop("Dane"));
    System.err.println(StringUtils.contains("Dorothy", "oro"));
    System.err.println(StringUtils.containsNone("r u m t", new char[] { 'r', 'o' }));
    System.err.println(StringUtils.containsOnly("r u m t", new char[] { 'r', 'o' }));
    System.err.println(StringUtils.countMatches("arthur", "r"));
    System.err.println(StringUtils.deleteWhitespace("f f f f"));
    System.err.println(StringUtils.difference("govern", "government"));
    System.err.println(StringUtils.getLevenshteinDistance("govern", "government"));

}

From source file:com.viettel.bankplus.merchantgw.dao.Authentication.java

public static void main(String[] args) throws Exception {
    String where = "where cp.request_date > :fromDate and cp.request_date < :toDate and bp.request_date > :fromDate and bp.request_date < :toDate and cp.content_provider_id in (:cpId) and bp.process_code = '300001'";
    int numparam = StringUtils.countMatches(where, ":");
    System.out.println(numparam);

}

From source file:com.adobe.acs.commons.version.impl.EvolutionPathUtil.java

public static int getDepthForPath(String path) {
    return StringUtils.countMatches(StringUtils.substringAfterLast(path, "jcr:frozenNode"), "/");
}

From source file:com.adobe.acs.commons.version.impl.EvolutionPathUtil.java

public static int getLastDepthForPath(String path) {
    return StringUtils.countMatches(StringUtils.substringAfterLast(path, "jcr:content"), "/");
}

From source file:commonUtils.FunctionUtils.java

public static int CountWordShow(String iWord, String iParagraph) {
    int NumOfWords = StringUtils.countMatches(iParagraph, iWord);
    return NumOfWords;
}

From source file:com.kstenschke.shifter.models.shiftertypes.JsVariablesDeclarations.java

/**
 * Check whether given string represents a declaration of JS variables:
 * -selection has multiple lines//  w  w w . j  av a 2  s  .com
 * -each trimmed line starts w/ "var" (at least 2 occurrences)
 * -each trimmed line ends w/ ";"
 * -there can be empty lines
 * -there can commented lines, beginning w/ "//"
 *
 * @param  str     String to be checked
 * @return boolean
 */
public static Boolean isJsVariables(String str) {
    str = str.trim();
    if (!str.startsWith("var") || !str.endsWith(";") || !str.contains("\n")
            || StringUtils.countMatches(str, "var") < 2 || StringUtils.countMatches(str, ";") < 2) {
        return false;
    }

    return true;
}

From source file:net.benelog.oneftpserver.util.NetworkUtilsTest.java

@Test
public void testGetLocalhostIp() {
    String ip = NetworkUtils.getLocalhostIp();
    int numOfDot = StringUtils.countMatches(ip, ".");
    assertThat(numOfDot, is(3));//  w ww .  j a  v a2s  .c o m
}