|
@@ -1,3 +1,4 @@
|
|
1
|
+package JavaStringCheese;
|
1
|
2
|
|
2
|
3
|
/**
|
3
|
4
|
* An introduction to Strings and String methods.
|
|
@@ -15,7 +16,9 @@ public class StringParser
|
15
|
16
|
*/
|
16
|
17
|
public static String upperCaseString(String s)
|
17
|
18
|
{
|
18
|
|
- return null;
|
|
19
|
+ String upperCase = s;
|
|
20
|
+ return upperCase.toUpperCase();
|
|
21
|
+
|
19
|
22
|
}
|
20
|
23
|
|
21
|
24
|
/**
|
|
@@ -26,7 +29,8 @@ public class StringParser
|
26
|
29
|
* @return String
|
27
|
30
|
*/
|
28
|
31
|
public static String lowerCaseString(String s) {
|
29
|
|
- return null;
|
|
32
|
+ String lowerCase = s;
|
|
33
|
+ return lowerCase.toLowerCase();
|
30
|
34
|
}
|
31
|
35
|
|
32
|
36
|
/**
|
|
@@ -37,7 +41,8 @@ public class StringParser
|
37
|
41
|
* @return String
|
38
|
42
|
*/
|
39
|
43
|
public static Character getFirstCharacter(String s) {
|
40
|
|
- return null;
|
|
44
|
+ String char1 = s;
|
|
45
|
+ return char1.charAt(0);
|
41
|
46
|
}
|
42
|
47
|
|
43
|
48
|
/**
|
|
@@ -49,7 +54,8 @@ public class StringParser
|
49
|
54
|
* @return String
|
50
|
55
|
*/
|
51
|
56
|
public static Character getNthCharacter(String s, Integer n) {
|
52
|
|
- return null;
|
|
57
|
+ String charN = s;
|
|
58
|
+ return charN.charAt(n);
|
53
|
59
|
}
|
54
|
60
|
|
55
|
61
|
/**
|
|
@@ -60,7 +66,9 @@ public class StringParser
|
60
|
66
|
* @return String
|
61
|
67
|
*/
|
62
|
68
|
public static String upperCaseFirstCharacter(String s) {
|
63
|
|
- return null;
|
|
69
|
+ String string1 = s;
|
|
70
|
+
|
|
71
|
+ return string1.substring(0,1).toUpperCase() + string1.substring(1);
|
64
|
72
|
}
|
65
|
73
|
|
66
|
74
|
/**
|
|
@@ -72,7 +80,14 @@ public class StringParser
|
72
|
80
|
* @return String
|
73
|
81
|
*/
|
74
|
82
|
public static String camelCaseString(String s) {
|
75
|
|
- return null;
|
|
83
|
+ String string1 = s;
|
|
84
|
+ int space = string1.indexOf(" ");
|
|
85
|
+ String string2 = string1.substring(0,1).toUpperCase();
|
|
86
|
+ String string3 = string1.substring(1, space).toLowerCase();
|
|
87
|
+ String string4 = string1.substring(space+1, space+2).toUpperCase();
|
|
88
|
+ String string5 = string1.substring(space+2).toLowerCase();
|
|
89
|
+
|
|
90
|
+ return string2 + string3 + string4 + string5;
|
76
|
91
|
}
|
77
|
92
|
|
78
|
93
|
/**
|
|
@@ -84,7 +99,15 @@ public class StringParser
|
84
|
99
|
* @return String
|
85
|
100
|
*/
|
86
|
101
|
public static String snakeCaseString(String s) {
|
87
|
|
- return null;
|
|
102
|
+ String string1 = s;
|
|
103
|
+ int space = string1.indexOf(" ");
|
|
104
|
+ String string2 = string1.substring(0,space).toLowerCase();
|
|
105
|
+ String string3 = string1.substring(space, space+1);
|
|
106
|
+ String string4 = "_";
|
|
107
|
+ String string5 = string1.substring(space+1).toLowerCase();
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+ return string2 + string4 + string5;
|
88
|
111
|
}
|
89
|
112
|
|
90
|
113
|
/**
|
|
@@ -95,7 +118,8 @@ public class StringParser
|
95
|
118
|
* @return String
|
96
|
119
|
*/
|
97
|
120
|
public static Integer getLength(String s) {
|
98
|
|
- return null;
|
|
121
|
+ String string1 = s;
|
|
122
|
+ return s.length();
|
99
|
123
|
}
|
100
|
124
|
|
101
|
125
|
/**
|
|
@@ -109,7 +133,9 @@ public class StringParser
|
109
|
133
|
* @return String
|
110
|
134
|
*/
|
111
|
135
|
public static Boolean isEqual(String s1, String s2) {
|
112
|
|
- return null;
|
|
136
|
+ String string1 = s1;
|
|
137
|
+ String string2 = s2;
|
|
138
|
+ return string1.equals(string2);
|
113
|
139
|
}
|
114
|
140
|
|
115
|
141
|
/**
|
|
@@ -123,6 +149,8 @@ public class StringParser
|
123
|
149
|
* @return String
|
124
|
150
|
*/
|
125
|
151
|
public static Boolean isEqualIgnoreCase(String s1, String s2) {
|
126
|
|
- return null;
|
|
152
|
+ String string1 = s1;
|
|
153
|
+ String string2 = s2;
|
|
154
|
+ return string1.equalsIgnoreCase(string2);
|
127
|
155
|
}
|
128
|
156
|
}
|