|
@@ -1,3 +1,4 @@
|
|
1
|
+import java.lang.*;
|
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, s.length());
|
64
|
65
|
}
|
65
|
66
|
|
66
|
67
|
/**
|
|
@@ -72,7 +73,15 @@ 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 split[] = s.split(" ");
|
|
78
|
+ String result = "";
|
|
79
|
+ for (int i = 0; i < split.length; i++) {
|
|
80
|
+ split[i].trim();
|
|
81
|
+ split[i] = split[i].substring(0,1).toUpperCase() + split[i].substring(1);
|
|
82
|
+ result = result + split[i];
|
|
83
|
+ }
|
|
84
|
+ return result;
|
76
|
85
|
}
|
77
|
86
|
|
78
|
87
|
/**
|
|
@@ -84,7 +93,7 @@ public class StringParser
|
84
|
93
|
* @return String
|
85
|
94
|
*/
|
86
|
95
|
public static String snakeCaseString(String s) {
|
87
|
|
- return null;
|
|
96
|
+ return s.toLowerCase().replace(" ", "_");
|
88
|
97
|
}
|
89
|
98
|
|
90
|
99
|
/**
|
|
@@ -95,7 +104,7 @@ public class StringParser
|
95
|
104
|
* @return String
|
96
|
105
|
*/
|
97
|
106
|
public static Integer getLength(String s) {
|
98
|
|
- return null;
|
|
107
|
+ return s.length();
|
99
|
108
|
}
|
100
|
109
|
|
101
|
110
|
/**
|
|
@@ -109,7 +118,11 @@ public class StringParser
|
109
|
118
|
* @return String
|
110
|
119
|
*/
|
111
|
120
|
public static Boolean isEqual(String s1, String s2) {
|
112
|
|
- return null;
|
|
121
|
+ if (s1.compareTo(s2) == 0) {
|
|
122
|
+ return true;
|
|
123
|
+ } else {
|
|
124
|
+ return false;
|
|
125
|
+ }
|
113
|
126
|
}
|
114
|
127
|
|
115
|
128
|
/**
|
|
@@ -123,6 +136,10 @@ public class StringParser
|
123
|
136
|
* @return String
|
124
|
137
|
*/
|
125
|
138
|
public static Boolean isEqualIgnoreCase(String s1, String s2) {
|
126
|
|
- return null;
|
|
139
|
+ if (s1.compareToIgnoreCase(s2) == 0) {
|
|
140
|
+ return true;
|
|
141
|
+ } else {
|
|
142
|
+ return false;
|
|
143
|
+ }
|
127
|
144
|
}
|
128
|
145
|
}
|