|
@@ -15,7 +15,7 @@ public class StringParser
|
15
|
15
|
*/
|
16
|
16
|
public static String upperCaseString(String s)
|
17
|
17
|
{
|
18
|
|
- return null;
|
|
18
|
+ return s.toUpperCase();
|
19
|
19
|
}
|
20
|
20
|
|
21
|
21
|
/**
|
|
@@ -26,7 +26,7 @@ public class StringParser
|
26
|
26
|
* @return String
|
27
|
27
|
*/
|
28
|
28
|
public static String lowerCaseString(String s) {
|
29
|
|
- return null;
|
|
29
|
+ return s.toLowerCase();
|
30
|
30
|
}
|
31
|
31
|
|
32
|
32
|
/**
|
|
@@ -37,7 +37,8 @@ public class StringParser
|
37
|
37
|
* @return String
|
38
|
38
|
*/
|
39
|
39
|
public static Character getFirstCharacter(String s) {
|
40
|
|
- return null;
|
|
40
|
+
|
|
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,10 @@ public class StringParser
|
60
|
61
|
* @return String
|
61
|
62
|
*/
|
62
|
63
|
public static String upperCaseFirstCharacter(String s) {
|
63
|
|
- return null;
|
|
64
|
+ // take substring of first and append the rest of the string
|
|
65
|
+ String capitalFirst = s.substring(0, 1).toUpperCase() + s.substring(1);
|
|
66
|
+
|
|
67
|
+ return capitalFirst;
|
64
|
68
|
}
|
65
|
69
|
|
66
|
70
|
/**
|
|
@@ -72,7 +76,17 @@ public class StringParser
|
72
|
76
|
* @return String
|
73
|
77
|
*/
|
74
|
78
|
public static String camelCaseString(String s) {
|
75
|
|
- return null;
|
|
79
|
+ // Split the string by empty space
|
|
80
|
+ // reconnect to a string
|
|
81
|
+ String words = "";
|
|
82
|
+ String[] camelCase = s.toLowerCase().split (" ");
|
|
83
|
+
|
|
84
|
+ for (int i = 0; i < camelCase.length; i ++) {
|
|
85
|
+ words += camelCase[i].substring(0, 1).toUpperCase() + camelCase[i].substring(1);
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ return words;
|
|
89
|
+
|
76
|
90
|
}
|
77
|
91
|
|
78
|
92
|
/**
|
|
@@ -84,7 +98,9 @@ public class StringParser
|
84
|
98
|
* @return String
|
85
|
99
|
*/
|
86
|
100
|
public static String snakeCaseString(String s) {
|
87
|
|
- return null;
|
|
101
|
+ String words = s.toLowerCase().replace(" ","_");
|
|
102
|
+
|
|
103
|
+ return words;
|
88
|
104
|
}
|
89
|
105
|
|
90
|
106
|
/**
|
|
@@ -95,7 +111,7 @@ public class StringParser
|
95
|
111
|
* @return String
|
96
|
112
|
*/
|
97
|
113
|
public static Integer getLength(String s) {
|
98
|
|
- return null;
|
|
114
|
+ return s.length();
|
99
|
115
|
}
|
100
|
116
|
|
101
|
117
|
/**
|
|
@@ -109,7 +125,7 @@ public class StringParser
|
109
|
125
|
* @return String
|
110
|
126
|
*/
|
111
|
127
|
public static Boolean isEqual(String s1, String s2) {
|
112
|
|
- return null;
|
|
128
|
+ return s1.equals(s2);
|
113
|
129
|
}
|
114
|
130
|
|
115
|
131
|
/**
|
|
@@ -123,6 +139,6 @@ public class StringParser
|
123
|
139
|
* @return String
|
124
|
140
|
*/
|
125
|
141
|
public static Boolean isEqualIgnoreCase(String s1, String s2) {
|
126
|
|
- return null;
|
|
142
|
+ return s1.toLowerCase().equals(s2.toLowerCase());
|
127
|
143
|
}
|
128
|
144
|
}
|