Browse Source

string methods

Yesoda Sanka 6 years ago
parent
commit
31495feaaf
2 changed files with 23 additions and 10 deletions
  1. BIN
      StringParser.class
  2. 23
    10
      StringParser.java

BIN
StringParser.class View File


+ 23
- 10
StringParser.java View File

@@ -4,6 +4,7 @@
4 4
  *
5 5
  * @author Wilhem Alcivar
6 6
  */
7
+
7 8
 public class StringParser
8 9
 {
9 10
     /**
@@ -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,9 @@ public class StringParser
60 61
      * @return String
61 62
      */
62 63
     public static String upperCaseFirstCharacter(String s) {
63
-        return null;
64
+        String str=s.toUpperCase();
65
+
66
+        return ""+str.charAt(0)+s.substring(1,s.length());
64 67
     }
65 68
 
66 69
     /**
@@ -72,7 +75,11 @@ public class StringParser
72 75
      * @return String
73 76
      */
74 77
     public static String camelCaseString(String s) {
75
-        return null;
78
+        //String slowerCase = s.toLowerCase ();
79
+        String [] list = s.split (" ");
80
+        String str1 = list[0];
81
+        String str2 = list[1];
82
+        return (""+str1.toUpperCase().charAt(0)+str1.toLowerCase().substring(1,str1.length())+str2.toUpperCase().charAt(0)+str2.toLowerCase().substring(1,str2.length()));
76 83
     }
77 84
 
78 85
     /**
@@ -84,7 +91,11 @@ public class StringParser
84 91
      * @return String
85 92
      */
86 93
     public static String snakeCaseString(String s) {
87
-        return null;
94
+        String [] list = s.split (" ");
95
+        String str1 = list[0].toLowerCase();
96
+        String str2 = list[1].toLowerCase();
97
+        
98
+        return str1+"_"+str2;
88 99
     }
89 100
 
90 101
     /**
@@ -95,7 +106,7 @@ public class StringParser
95 106
      * @return String
96 107
      */
97 108
     public static Integer getLength(String s) {
98
-        return null;
109
+        return s.length();
99 110
     }
100 111
 
101 112
     /**
@@ -109,7 +120,8 @@ public class StringParser
109 120
      * @return String
110 121
      */
111 122
     public static Boolean isEqual(String s1, String s2) {
112
-        return null;
123
+
124
+        return s1.contentEquals(new StringBuffer (s2));
113 125
     }
114 126
 
115 127
     /**
@@ -123,6 +135,7 @@ public class StringParser
123 135
      * @return String
124 136
      */
125 137
     public static Boolean isEqualIgnoreCase(String s1, String s2) {
126
-        return null;
138
+
139
+        return s1.equalsIgnoreCase(s2);
127 140
     }
128 141
 }