Java String Starts Wtih startsWithCapLettersEndsWithDigits(String text)

Here you can find the source of startsWithCapLettersEndsWithDigits(String text)

Description

Determine if a string starts with capital letter(s) and ends with digit(s).

License

Open Source License

Parameter

Parameter Description
text String to parse

Return

true if name starts with capital letter(s) and ends with digit(s), false otherwise

Declaration

public static boolean startsWithCapLettersEndsWithDigits(String text) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from  w  ww. jav a  2s . c om*/
     * Determine if a string starts with capital letter(s) and ends with
     * digit(s).
     *
     * @param text String to parse
     *
     * @return true if name starts with capital letter(s) and ends with
     *         digit(s), false otherwise
     */
    public static boolean startsWithCapLettersEndsWithDigits(String text) {
        boolean result = false;
        if (!isNullOrEmpty(text, true)) {
            char[] cs = text.toCharArray();
            int j = 0;
            while ((j < cs.length) && (Character.isUpperCase(cs[j]))) {
                j++;
            }
            if ((j == 0) || (j == cs.length)) {
                result = false;
            } else {
                result = digitsOnly(text.substring(j));
            }
        }
        return result;
    }

    /**
     * Determines if a String is null or empty
     *
     * @param text text to examine
     * @param trim whether to trim the text before testing it's content
     *
     * @return true if text is null or empty, false otherwise
     */
    public static boolean isNullOrEmpty(String text, boolean trim) {
        boolean result = true;
        if (text != null) {
            String data = text;
            if (trim) {
                data = data.trim();
            }
            if (data.length() > 0) {
                result = false;
            }
        }
        return result;
    }

    /**
     * Determine if a string contains digit(s) only
     *
     * @param text String to parse
     *
     * @return true if text contains only digit(s), false otherwise
     */
    public static boolean digitsOnly(String text) {
        boolean result = true;
        if (isNullOrEmpty(text, true)) {
            result = false;
        } else {
            char[] c = text.toCharArray();
            int j = 0;
            while ((result) && (j < c.length)) {
                if (!Character.isDigit(c[j])) {
                    result = false;
                }
                ++j;
            }
        }
        return result;
    }
}

Related

  1. startsWithAnyIgnoreCase(String s, String... options)
  2. startsWithAnyIgnoreCase(String string, String... searchStrings)
  3. startsWithAnyOfThose(final String in, final String[] prefixes)
  4. startsWithAt(String text, String toFind, int offset)
  5. startsWithCamelCase(String string, String prefix)
  6. startsWithChar(CharSequence s, char prefix)
  7. startsWithChar(final String s, final char c)
  8. startsWithChar(String s, char c)
  9. startsWithChar(String string, char prefix)