|
@@ -6,6 +6,7 @@
|
6
|
6
|
*/
|
7
|
7
|
public class StringParser
|
8
|
8
|
{
|
|
9
|
+ private static String s1;
|
9
|
10
|
/**
|
10
|
11
|
* Takes a String and returns that String with all characters uppercased.
|
11
|
12
|
* E.G. cat would become CAT. dOnUt would become DONUT.
|
|
@@ -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,8 @@ public class StringParser
|
60
|
61
|
* @return String
|
61
|
62
|
*/
|
62
|
63
|
public static String upperCaseFirstCharacter(String s) {
|
63
|
|
- return null;
|
|
64
|
+ s1 = s.substring(0,1).toUpperCase() + s.substring(1);
|
|
65
|
+ return s1;
|
64
|
66
|
}
|
65
|
67
|
|
66
|
68
|
/**
|
|
@@ -72,6 +74,22 @@ public class StringParser
|
72
|
74
|
* @return String
|
73
|
75
|
*/
|
74
|
76
|
public static String camelCaseString(String s) {
|
|
77
|
+ //String s2 = "";
|
|
78
|
+ s1 = s.toLowerCase();
|
|
79
|
+ //s1 = s1.subString(0,1) + s1.subString(1);
|
|
80
|
+ //StringBuffer bf = new StringBuffer(s1);
|
|
81
|
+ for(int i=0;i<s1.length();i++)
|
|
82
|
+ {
|
|
83
|
+ if(s1.charAt(i) == ' '){
|
|
84
|
+ s=s1.substring(0,1).toUpperCase()+s1.substring(1,i);
|
|
85
|
+ s1=s1.substring(i+1,i+2).toUpperCase()+s1.substring(i+2);
|
|
86
|
+ return s+s1;
|
|
87
|
+ }
|
|
88
|
+ else{
|
|
89
|
+ s=s1.substring(0,1).toUpperCase()+s1.substring(1);
|
|
90
|
+ }
|
|
91
|
+ }
|
|
92
|
+
|
75
|
93
|
return null;
|
76
|
94
|
}
|
77
|
95
|
|
|
@@ -84,7 +102,19 @@ public class StringParser
|
84
|
102
|
* @return String
|
85
|
103
|
*/
|
86
|
104
|
public static String snakeCaseString(String s) {
|
87
|
|
- return null;
|
|
105
|
+
|
|
106
|
+ StringBuffer bf = new StringBuffer(s.toLowerCase());
|
|
107
|
+ for(int i=0;i<bf.length();i++)
|
|
108
|
+ {
|
|
109
|
+ if(bf.charAt(i) == ' ')
|
|
110
|
+ {
|
|
111
|
+ bf.insert(i,"_");
|
|
112
|
+ bf.deleteCharAt(i+1);
|
|
113
|
+ s= bf.toString();
|
|
114
|
+ return s;
|
|
115
|
+ }
|
|
116
|
+ }
|
|
117
|
+ return s;
|
88
|
118
|
}
|
89
|
119
|
|
90
|
120
|
/**
|
|
@@ -95,7 +125,7 @@ public class StringParser
|
95
|
125
|
* @return String
|
96
|
126
|
*/
|
97
|
127
|
public static Integer getLength(String s) {
|
98
|
|
- return null;
|
|
128
|
+ return s.length();
|
99
|
129
|
}
|
100
|
130
|
|
101
|
131
|
/**
|
|
@@ -109,7 +139,7 @@ public class StringParser
|
109
|
139
|
* @return String
|
110
|
140
|
*/
|
111
|
141
|
public static Boolean isEqual(String s1, String s2) {
|
112
|
|
- return null;
|
|
142
|
+ return s1.equals(s2);
|
113
|
143
|
}
|
114
|
144
|
|
115
|
145
|
/**
|
|
@@ -123,6 +153,6 @@ public class StringParser
|
123
|
153
|
* @return String
|
124
|
154
|
*/
|
125
|
155
|
public static Boolean isEqualIgnoreCase(String s1, String s2) {
|
126
|
|
- return null;
|
|
156
|
+ return s1.equalsIgnoreCase(s2);
|
127
|
157
|
}
|
128
|
158
|
}
|