|
|
@@ -15,7 +15,8 @@ public class StringParser
|
|
15
|
15
|
*/
|
|
16
|
16
|
public static String upperCaseString(String s)
|
|
17
|
17
|
{
|
|
18
|
|
- return null;
|
|
|
18
|
+ String abc = s.toUpperCase();
|
|
|
19
|
+ return abc;
|
|
19
|
20
|
}
|
|
20
|
21
|
|
|
21
|
22
|
/**
|
|
|
@@ -26,7 +27,8 @@ public class StringParser
|
|
26
|
27
|
* @return String
|
|
27
|
28
|
*/
|
|
28
|
29
|
public static String lowerCaseString(String s) {
|
|
29
|
|
- return null;
|
|
|
30
|
+ String abc = s.toLowerCase();
|
|
|
31
|
+ return abc;
|
|
30
|
32
|
}
|
|
31
|
33
|
|
|
32
|
34
|
/**
|
|
|
@@ -37,10 +39,11 @@ public class StringParser
|
|
37
|
39
|
* @return String
|
|
38
|
40
|
*/
|
|
39
|
41
|
public static Character getFirstCharacter(String s) {
|
|
40
|
|
- return null;
|
|
|
42
|
+ char first= s.charAt(0);
|
|
|
43
|
+ return first;
|
|
41
|
44
|
}
|
|
42
|
45
|
|
|
43
|
|
- /**
|
|
|
46
|
+ /*
|
|
44
|
47
|
* Takes a String and returns the character at index n of that string.
|
|
45
|
48
|
* E.G. cat, 2 would return t. Embark, 4 would return r.
|
|
46
|
49
|
*
|
|
|
@@ -48,22 +51,28 @@ public class StringParser
|
|
48
|
51
|
* @param n
|
|
49
|
52
|
* @return String
|
|
50
|
53
|
*/
|
|
51
|
|
- public static Character getNthCharacter(String s, Integer n) {
|
|
52
|
|
- return null;
|
|
53
|
|
- }
|
|
54
|
54
|
|
|
55
|
|
- /**
|
|
|
55
|
+ public static Character getNthCharacter(String s, Integer n) {
|
|
|
56
|
+ char fir = s.charAt(n);
|
|
|
57
|
+
|
|
|
58
|
+ return fir;
|
|
|
59
|
+ }
|
|
|
60
|
+
|
|
|
61
|
+ /*
|
|
56
|
62
|
* Takes a String and returns that string with the first character uppercased.
|
|
57
|
63
|
* E.G. cat would return Cat. cofFee would return CofFee.
|
|
58
|
64
|
*
|
|
59
|
65
|
* @param s
|
|
60
|
66
|
* @return String
|
|
|
67
|
+ *
|
|
61
|
68
|
*/
|
|
62
|
69
|
public static String upperCaseFirstCharacter(String s) {
|
|
63
|
|
- return null;
|
|
|
70
|
+ String capital = s.substring(0, 1).toUpperCase() + s.substring(1);
|
|
|
71
|
+ return capital;
|
|
|
72
|
+
|
|
64
|
73
|
}
|
|
65
|
74
|
|
|
66
|
|
- /**
|
|
|
75
|
+ /*
|
|
67
|
76
|
* Takes a String and returns that string with the first character of each word in it uppercased
|
|
68
|
77
|
* and then joined.
|
|
69
|
78
|
* E.G. dog whistle would return DogWhistle. adjuNCT pRoFessOR would return AdjuctProfessor.
|
|
|
@@ -72,10 +81,21 @@ public class StringParser
|
|
72
|
81
|
* @return String
|
|
73
|
82
|
*/
|
|
74
|
83
|
public static String camelCaseString(String s) {
|
|
75
|
|
- return null;
|
|
|
84
|
+ String sum=s.toLowerCase();
|
|
|
85
|
+
|
|
|
86
|
+ String first=sum.split(" ")[0];
|
|
|
87
|
+ String sec=sum.split(" ")[1];
|
|
|
88
|
+
|
|
|
89
|
+ String firstLet = first.substring(0,1).toUpperCase()+first.substring(1).toLowerCase();
|
|
|
90
|
+ String othLetters = sec.substring(0,1).toUpperCase()+sec.substring(1).toLowerCase();
|
|
|
91
|
+ String total=firstLet+othLetters;
|
|
|
92
|
+ return total ;
|
|
76
|
93
|
}
|
|
77
|
94
|
|
|
78
|
|
- /**
|
|
|
95
|
+
|
|
|
96
|
+
|
|
|
97
|
+
|
|
|
98
|
+ /*
|
|
79
|
99
|
* Takes a String and returns that string with each character lowercased
|
|
80
|
100
|
* and then joined with an underscore
|
|
81
|
101
|
* E.G. dog whistle would return dog_whistle. adjuNCT pRoFessOR would return adjuct_professor.
|
|
|
@@ -84,7 +104,19 @@ public class StringParser
|
|
84
|
104
|
* @return String
|
|
85
|
105
|
*/
|
|
86
|
106
|
public static String snakeCaseString(String s) {
|
|
87
|
|
- return null;
|
|
|
107
|
+
|
|
|
108
|
+ int snakeCase = s.length();
|
|
|
109
|
+ String Sti = "";
|
|
|
110
|
+
|
|
|
111
|
+ for (int n = 0; n < snakeCase; n++){
|
|
|
112
|
+ if (s.charAt (n) == ' '){
|
|
|
113
|
+ Sti = Sti + '_';
|
|
|
114
|
+ }
|
|
|
115
|
+ else
|
|
|
116
|
+ Sti = Sti + Character.toLowerCase (s.charAt(n));
|
|
|
117
|
+ }
|
|
|
118
|
+
|
|
|
119
|
+ return Sti;
|
|
88
|
120
|
}
|
|
89
|
121
|
|
|
90
|
122
|
/**
|
|
|
@@ -94,8 +126,10 @@ public class StringParser
|
|
94
|
126
|
* @param s
|
|
95
|
127
|
* @return String
|
|
96
|
128
|
*/
|
|
|
129
|
+
|
|
97
|
130
|
public static Integer getLength(String s) {
|
|
98
|
|
- return null;
|
|
|
131
|
+ return s.length();
|
|
|
132
|
+
|
|
99
|
133
|
}
|
|
100
|
134
|
|
|
101
|
135
|
/**
|
|
|
@@ -109,7 +143,11 @@ public class StringParser
|
|
109
|
143
|
* @return String
|
|
110
|
144
|
*/
|
|
111
|
145
|
public static Boolean isEqual(String s1, String s2) {
|
|
112
|
|
- return null;
|
|
|
146
|
+ if(s1.equals(s2)) {
|
|
|
147
|
+ return true;
|
|
|
148
|
+ } else {
|
|
|
149
|
+ return false;
|
|
|
150
|
+ }
|
|
113
|
151
|
}
|
|
114
|
152
|
|
|
115
|
153
|
/**
|
|
|
@@ -123,6 +161,11 @@ public class StringParser
|
|
123
|
161
|
* @return String
|
|
124
|
162
|
*/
|
|
125
|
163
|
public static Boolean isEqualIgnoreCase(String s1, String s2) {
|
|
126
|
|
- return null;
|
|
|
164
|
+ if (s1.equalsIgnoreCase(s2)){
|
|
|
165
|
+ return true;
|
|
|
166
|
+ } else {
|
|
|
167
|
+ return false;
|
|
|
168
|
+ }
|
|
|
169
|
+
|
|
127
|
170
|
}
|
|
128
|
171
|
}
|