|
|
@@ -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
|
+ char firstLet= s.charAt(0);
|
|
|
41
|
+ return firstLet;
|
|
41
|
42
|
}
|
|
42
|
43
|
|
|
43
|
44
|
/**
|
|
|
@@ -49,7 +50,8 @@ public class StringParser
|
|
49
|
50
|
* @return String
|
|
50
|
51
|
*/
|
|
51
|
52
|
public static Character getNthCharacter(String s, Integer n) {
|
|
52
|
|
- return null;
|
|
|
53
|
+ char val=s.charAt(n);
|
|
|
54
|
+ return val;
|
|
53
|
55
|
}
|
|
54
|
56
|
|
|
55
|
57
|
/**
|
|
|
@@ -60,7 +62,8 @@ public class StringParser
|
|
60
|
62
|
* @return String
|
|
61
|
63
|
*/
|
|
62
|
64
|
public static String upperCaseFirstCharacter(String s) {
|
|
63
|
|
- return null;
|
|
|
65
|
+ String cap = s.substring(0, 1).toUpperCase() + s.substring(1);
|
|
|
66
|
+ return cap;
|
|
64
|
67
|
}
|
|
65
|
68
|
|
|
66
|
69
|
/**
|
|
|
@@ -71,8 +74,14 @@ public class StringParser
|
|
71
|
74
|
* @param s
|
|
72
|
75
|
* @return String
|
|
73
|
76
|
*/
|
|
74
|
|
- public static String camelCaseString(String s) {
|
|
75
|
|
- return null;
|
|
|
77
|
+ public static String camelCaseString(String s){
|
|
|
78
|
+ String sum=s.toLowerCase();
|
|
|
79
|
+ String part1= sum.split(" ")[0];
|
|
|
80
|
+ String part2= sum.split(" ")[1];
|
|
|
81
|
+ String firstHalf= part1.substring(0, 1).toUpperCase() + part1.substring(1).toLowerCase();
|
|
|
82
|
+ String secondHalf= part2.substring(0, 1).toUpperCase() + part2.substring(1).toLowerCase();
|
|
|
83
|
+ String theSum=firstHalf+secondHalf;
|
|
|
84
|
+ return theSum;
|
|
76
|
85
|
}
|
|
77
|
86
|
|
|
78
|
87
|
/**
|
|
|
@@ -84,8 +93,23 @@ public class StringParser
|
|
84
|
93
|
* @return String
|
|
85
|
94
|
*/
|
|
86
|
95
|
public static String snakeCaseString(String s) {
|
|
87
|
|
- return null;
|
|
88
|
|
- }
|
|
|
96
|
+ int n = s.length();
|
|
|
97
|
+ String str1 = "";
|
|
|
98
|
+
|
|
|
99
|
+ for (int i = 0; i < n; i++)
|
|
|
100
|
+ {
|
|
|
101
|
+ // Converting space
|
|
|
102
|
+ // to underscor
|
|
|
103
|
+ if (s.charAt(i) == ' ')
|
|
|
104
|
+ str1 = str1 + '_';
|
|
|
105
|
+ else
|
|
|
106
|
+ // If not space, convert
|
|
|
107
|
+ // into lower character
|
|
|
108
|
+ str1 = str1 +
|
|
|
109
|
+ Character.toLowerCase(s.charAt(i));
|
|
|
110
|
+ }
|
|
|
111
|
+ return str1;
|
|
|
112
|
+ }
|
|
89
|
113
|
|
|
90
|
114
|
/**
|
|
91
|
115
|
* Takes a String and returns the length of that string
|
|
|
@@ -95,7 +119,7 @@ public class StringParser
|
|
95
|
119
|
* @return String
|
|
96
|
120
|
*/
|
|
97
|
121
|
public static Integer getLength(String s) {
|
|
98
|
|
- return null;
|
|
|
122
|
+ return s.length();
|
|
99
|
123
|
}
|
|
100
|
124
|
|
|
101
|
125
|
/**
|
|
|
@@ -109,7 +133,11 @@ public class StringParser
|
|
109
|
133
|
* @return String
|
|
110
|
134
|
*/
|
|
111
|
135
|
public static Boolean isEqual(String s1, String s2) {
|
|
112
|
|
- return null;
|
|
|
136
|
+ if(s1.equals(s2)){
|
|
|
137
|
+ return true;
|
|
|
138
|
+ } else {
|
|
|
139
|
+ return false;
|
|
|
140
|
+ }
|
|
113
|
141
|
}
|
|
114
|
142
|
|
|
115
|
143
|
/**
|
|
|
@@ -123,6 +151,10 @@ public class StringParser
|
|
123
|
151
|
* @return String
|
|
124
|
152
|
*/
|
|
125
|
153
|
public static Boolean isEqualIgnoreCase(String s1, String s2) {
|
|
126
|
|
- return null;
|
|
|
154
|
+ if(s1.equalsIgnoreCase(s2)){
|
|
|
155
|
+ return true;
|
|
|
156
|
+ } else {
|
|
|
157
|
+ return false;
|
|
|
158
|
+ }
|
|
127
|
159
|
}
|
|
128
|
160
|
}
|