|
@@ -4,20 +4,30 @@
|
4
|
4
|
*
|
5
|
5
|
* @author Wilhem Alcivar
|
6
|
6
|
*/
|
|
7
|
+
|
|
8
|
+import java.util.*;
|
|
9
|
+
|
|
10
|
+
|
7
|
11
|
public class StringParser
|
8
|
12
|
{
|
9
|
|
- /**
|
10
|
|
- * Takes a String and returns that String with all characters uppercased.
|
11
|
|
- * E.G. cat would become CAT. dOnUt would become DONUT.
|
12
|
|
- *
|
13
|
|
- * @param s
|
14
|
|
- * @return String
|
15
|
|
- */
|
16
|
|
- public static String upperCaseString(String s)
|
17
|
|
- {
|
18
|
|
- return null;
|
|
13
|
+ public static String upperCaseString(String s) {
|
|
14
|
+
|
|
15
|
+ return s.toUpperCase();
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
19
|
21
|
}
|
20
|
|
-
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
21
|
31
|
/**
|
22
|
32
|
* Takes a String and returns that String with all characters lowercased.
|
23
|
33
|
* E.G. MOUSE would become mouse. dOnUt would become donut.
|
|
@@ -26,20 +36,29 @@ public class StringParser
|
26
|
36
|
* @return String
|
27
|
37
|
*/
|
28
|
38
|
public static String lowerCaseString(String s) {
|
29
|
|
- return null;
|
|
39
|
+
|
|
40
|
+ return s.toLowerCase();
|
|
41
|
+
|
|
42
|
+
|
30
|
43
|
}
|
31
|
|
-
|
|
44
|
+
|
|
45
|
+
|
32
|
46
|
/**
|
33
|
47
|
* Takes a String and returns the first character of that string.
|
34
|
48
|
* E.G. cat would return c. Embark would return E.
|
35
|
49
|
*
|
36
|
50
|
* @param s
|
37
|
51
|
* @return String
|
|
52
|
+ *
|
38
|
53
|
*/
|
|
54
|
+
|
39
|
55
|
public static Character getFirstCharacter(String s) {
|
40
|
|
- return null;
|
41
|
|
- }
|
42
|
|
-
|
|
56
|
+
|
|
57
|
+ return s.charAt(0);
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+}
|
43
|
62
|
/**
|
44
|
63
|
* Takes a String and returns the character at index n of that string.
|
45
|
64
|
* E.G. cat, 2 would return t. Embark, 4 would return r.
|
|
@@ -49,7 +68,9 @@ public class StringParser
|
49
|
68
|
* @return String
|
50
|
69
|
*/
|
51
|
70
|
public static Character getNthCharacter(String s, Integer n) {
|
52
|
|
- return null;
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+ return s.charAt(n);
|
53
|
74
|
}
|
54
|
75
|
|
55
|
76
|
/**
|
|
@@ -60,7 +81,15 @@ public class StringParser
|
60
|
81
|
* @return String
|
61
|
82
|
*/
|
62
|
83
|
public static String upperCaseFirstCharacter(String s) {
|
63
|
|
- return null;
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+ //t = Character.toUpperCase(t.charAt(0)) + t.substring(1);
|
|
87
|
+
|
|
88
|
+ //System.out.println(t);
|
|
89
|
+ return (s.substring (0,1)).toUpperCase() + s.substring(1);
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
64
|
93
|
}
|
65
|
94
|
|
66
|
95
|
/**
|
|
@@ -72,7 +101,22 @@ public class StringParser
|
72
|
101
|
* @return String
|
73
|
102
|
*/
|
74
|
103
|
public static String camelCaseString(String s) {
|
75
|
|
- return null;
|
|
104
|
+ String [] words = s.split(" ");
|
|
105
|
+
|
|
106
|
+ String t = "";
|
|
107
|
+ int i;
|
|
108
|
+ //String firstWord;
|
|
109
|
+ for ( i = 0; i < words.length; i ++) {
|
|
110
|
+
|
|
111
|
+ t += words[i].substring (0,1).toUpperCase() + words[i].substring(1).toLowerCase() ;
|
|
112
|
+
|
|
113
|
+ //t.join(firstWord);
|
|
114
|
+ }
|
|
115
|
+ //String nextWord = words[1].substring (0,1).toUpperCase() + words[1].substring(1).toLowerCase();
|
|
116
|
+
|
|
117
|
+ //String nextWord2 = words[2].substring (0,1).toUpperCase() + words[2].substring(1).toLowerCase();
|
|
118
|
+ return t;
|
|
119
|
+
|
76
|
120
|
}
|
77
|
121
|
|
78
|
122
|
/**
|
|
@@ -84,8 +128,13 @@ public class StringParser
|
84
|
128
|
* @return String
|
85
|
129
|
*/
|
86
|
130
|
public static String snakeCaseString(String s) {
|
87
|
|
- return null;
|
|
131
|
+ return s.replaceAll(" ", "_").toLowerCase();
|
|
132
|
+
|
88
|
133
|
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
89
|
138
|
|
90
|
139
|
/**
|
91
|
140
|
* Takes a String and returns the length of that string
|
|
@@ -95,7 +144,7 @@ public class StringParser
|
95
|
144
|
* @return String
|
96
|
145
|
*/
|
97
|
146
|
public static Integer getLength(String s) {
|
98
|
|
- return null;
|
|
147
|
+ return s.length();
|
99
|
148
|
}
|
100
|
149
|
|
101
|
150
|
/**
|
|
@@ -109,7 +158,10 @@ public class StringParser
|
109
|
158
|
* @return String
|
110
|
159
|
*/
|
111
|
160
|
public static Boolean isEqual(String s1, String s2) {
|
112
|
|
- return null;
|
|
161
|
+ if (s1.equals(s2)) {
|
|
162
|
+ return true;
|
|
163
|
+ } else return false;
|
|
164
|
+
|
113
|
165
|
}
|
114
|
166
|
|
115
|
167
|
/**
|
|
@@ -123,6 +175,11 @@ public class StringParser
|
123
|
175
|
* @return String
|
124
|
176
|
*/
|
125
|
177
|
public static Boolean isEqualIgnoreCase(String s1, String s2) {
|
126
|
|
- return null;
|
127
|
|
- }
|
|
178
|
+ if (s1.equalsIgnoreCase(s2)){
|
|
179
|
+
|
|
180
|
+ return true;
|
|
181
|
+
|
|
182
|
+ }
|
|
183
|
+ else return false;
|
|
184
|
+ }
|
128
|
185
|
}
|