123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- package JavaStringCheese;
-
- /**
- * An introduction to Strings and String methods.
- *
- * @author Wilhem Alcivar
- */
- public class StringParser
- {
- /**
- * Takes a String and returns that String with all characters uppercased.
- * E.G. cat would become CAT. dOnUt would become DONUT.
- *
- * @param s
- * @return String
- */
- public static String upperCaseString(String s)
- {
- String upperCase = s;
- return upperCase.toUpperCase();
-
- }
-
- /**
- * Takes a String and returns that String with all characters lowercased.
- * E.G. MOUSE would become mouse. dOnUt would become donut.
- *
- * @param s
- * @return String
- */
- public static String lowerCaseString(String s) {
- String lowerCase = s;
- return lowerCase.toLowerCase();
- }
-
- /**
- * Takes a String and returns the first character of that string.
- * E.G. cat would return c. Embark would return E.
- *
- * @param s
- * @return String
- */
- public static Character getFirstCharacter(String s) {
- String char1 = s;
- return char1.charAt(0);
- }
-
- /**
- * Takes a String and returns the character at index n of that string.
- * E.G. cat, 2 would return t. Embark, 4 would return r.
- *
- * @param s
- * @param n
- * @return String
- */
- public static Character getNthCharacter(String s, Integer n) {
- String charN = s;
- return charN.charAt(n);
- }
-
- /**
- * Takes a String and returns that string with the first character uppercased.
- * E.G. cat would return Cat. cofFee would return CofFee.
- *
- * @param s
- * @return String
- */
- public static String upperCaseFirstCharacter(String s) {
- String string1 = s;
-
- return string1.substring(0,1).toUpperCase() + string1.substring(1);
- }
-
- /**
- * Takes a String and returns that string with the first character of each word in it uppercased
- * and then joined.
- * E.G. dog whistle would return DogWhistle. adjuNCT pRoFessOR would return AdjuctProfessor.
- *
- * @param s
- * @return String
- */
- public static String camelCaseString(String s) {
- String string1 = s;
- int space = string1.indexOf(" ");
- String string2 = string1.substring(0,1).toUpperCase();
- String string3 = string1.substring(1, space).toLowerCase();
- String string4 = string1.substring(space+1, space+2).toUpperCase();
- String string5 = string1.substring(space+2).toLowerCase();
-
- return string2 + string3 + string4 + string5;
- }
-
- /**
- * Takes a String and returns that string with each character lowercased
- * and then joined with an underscore
- * E.G. dog whistle would return dog_whistle. adjuNCT pRoFessOR would return adjuct_professor.
- *
- * @param s
- * @return String
- */
- public static String snakeCaseString(String s) {
- String string1 = s;
- int space = string1.indexOf(" ");
- String string2 = string1.substring(0,space).toLowerCase();
- String string3 = string1.substring(space, space+1);
- String string4 = "_";
- String string5 = string1.substring(space+1).toLowerCase();
-
-
- return string2 + string4 + string5;
- }
-
- /**
- * Takes a String and returns the length of that string
- * E.G. cat would return 3. extra would return 5.
- *
- * @param s
- * @return String
- */
- public static Integer getLength(String s) {
- String string1 = s;
- return s.length();
- }
-
- /**
- * Takes in two strings and returns true if they are equal
- * E.G. example and shelf would return false.
- * cat and CaT would return false.
- * Dog and Dog would return true
- *
- * @param s1
- * @param s2
- * @return String
- */
- public static Boolean isEqual(String s1, String s2) {
- String string1 = s1;
- String string2 = s2;
- return string1.equals(string2);
- }
-
- /**
- * Takes in two strings and returns true if they are equal
- * E.G. example and shelf would return false.
- * cat and CaT would return true.
- * Dog and Dog would return true
- *
- * @param s1
- * @param s2
- * @return String
- */
- public static Boolean isEqualIgnoreCase(String s1, String s2) {
- String string1 = s1;
- String string2 = s2;
- return string1.equalsIgnoreCase(string2);
- }
- }
|