|
@@ -1,3 +1,4 @@
|
|
1
|
+package JavaStringCheese;
|
1
|
2
|
|
2
|
3
|
/**
|
3
|
4
|
* An introduction to Strings and String methods.
|
|
@@ -15,7 +16,7 @@ public class StringParser
|
15
|
16
|
*/
|
16
|
17
|
public static String upperCaseString(String s)
|
17
|
18
|
{
|
18
|
|
- return null;
|
|
19
|
+ return s.toUpperCase();
|
19
|
20
|
}
|
20
|
21
|
|
21
|
22
|
/**
|
|
@@ -26,7 +27,7 @@ public class StringParser
|
26
|
27
|
* @return String
|
27
|
28
|
*/
|
28
|
29
|
public static String lowerCaseString(String s) {
|
29
|
|
- return null;
|
|
30
|
+ return s.toLowerCase();
|
30
|
31
|
}
|
31
|
32
|
|
32
|
33
|
/**
|
|
@@ -37,7 +38,7 @@ public class StringParser
|
37
|
38
|
* @return String
|
38
|
39
|
*/
|
39
|
40
|
public static Character getFirstCharacter(String s) {
|
40
|
|
- return null;
|
|
41
|
+ return s.charAt(0);
|
41
|
42
|
}
|
42
|
43
|
|
43
|
44
|
/**
|
|
@@ -49,7 +50,7 @@ public class StringParser
|
49
|
50
|
* @return String
|
50
|
51
|
*/
|
51
|
52
|
public static Character getNthCharacter(String s, Integer n) {
|
52
|
|
- return null;
|
|
53
|
+ return s.charAt(n);
|
53
|
54
|
}
|
54
|
55
|
|
55
|
56
|
/**
|
|
@@ -60,7 +61,7 @@ public class StringParser
|
60
|
61
|
* @return String
|
61
|
62
|
*/
|
62
|
63
|
public static String upperCaseFirstCharacter(String s) {
|
63
|
|
- return null;
|
|
64
|
+ return s.substring(0, 1).toUpperCase() + s.substring(1);
|
64
|
65
|
}
|
65
|
66
|
|
66
|
67
|
/**
|
|
@@ -72,7 +73,14 @@ public class StringParser
|
72
|
73
|
* @return String
|
73
|
74
|
*/
|
74
|
75
|
public static String camelCaseString(String s) {
|
75
|
|
- return null;
|
|
76
|
+ s = s.toLowerCase();
|
|
77
|
+ String camelCase = new String();
|
|
78
|
+ int word2 = s.indexOf(" ") + 1;
|
|
79
|
+
|
|
80
|
+ camelCase = s.substring(0, 1).toUpperCase() + s.substring(1, word2 - 1 ) +
|
|
81
|
+ s.substring(word2, word2 + 1).toUpperCase() + s.substring(word2 +1);
|
|
82
|
+
|
|
83
|
+ return camelCase;
|
76
|
84
|
}
|
77
|
85
|
|
78
|
86
|
/**
|
|
@@ -84,7 +92,9 @@ public class StringParser
|
84
|
92
|
* @return String
|
85
|
93
|
*/
|
86
|
94
|
public static String snakeCaseString(String s) {
|
87
|
|
- return null;
|
|
95
|
+ String str = s.toLowerCase().replace(" ","_");
|
|
96
|
+
|
|
97
|
+ return str;
|
88
|
98
|
}
|
89
|
99
|
|
90
|
100
|
/**
|
|
@@ -95,7 +105,7 @@ public class StringParser
|
95
|
105
|
* @return String
|
96
|
106
|
*/
|
97
|
107
|
public static Integer getLength(String s) {
|
98
|
|
- return null;
|
|
108
|
+ return s.length();
|
99
|
109
|
}
|
100
|
110
|
|
101
|
111
|
/**
|
|
@@ -109,7 +119,14 @@ public class StringParser
|
109
|
119
|
* @return String
|
110
|
120
|
*/
|
111
|
121
|
public static Boolean isEqual(String s1, String s2) {
|
112
|
|
- return null;
|
|
122
|
+ boolean isIt = false;
|
|
123
|
+
|
|
124
|
+ if (s1 == s2){
|
|
125
|
+ isIt = true;
|
|
126
|
+
|
|
127
|
+ }
|
|
128
|
+
|
|
129
|
+ return isIt;
|
113
|
130
|
}
|
114
|
131
|
|
115
|
132
|
/**
|
|
@@ -123,6 +140,13 @@ public class StringParser
|
123
|
140
|
* @return String
|
124
|
141
|
*/
|
125
|
142
|
public static Boolean isEqualIgnoreCase(String s1, String s2) {
|
126
|
|
- return null;
|
|
143
|
+ boolean isIt = false;
|
|
144
|
+
|
|
145
|
+ if (s1.equalsIgnoreCase(s2)){
|
|
146
|
+ isIt = true;
|
|
147
|
+
|
|
148
|
+ }
|
|
149
|
+
|
|
150
|
+ return isIt;
|
127
|
151
|
}
|
128
|
152
|
}
|