4
4
* Created By AMIT JANGID
5
5
* 2018 April 17 - Tuesday - 12:52 PM
6
6
**/
7
-
7
+ @ SuppressWarnings ( "unused" )
8
8
public class TextUtilities
9
9
{
10
10
/**
@@ -14,19 +14,21 @@ public class TextUtilities
14
14
* @param string - string where you want to replace null
15
15
* @return it will return empty string
16
16
**/
17
- public static String replaceNull (String string )
17
+ public static String replaceNullWithEmpty (String string )
18
18
{
19
19
if (string == null )
20
20
{
21
21
return "" ;
22
22
}
23
-
24
- if (string .equalsIgnoreCase ("null" ))
23
+ else if (string .equalsIgnoreCase ("null" ))
25
24
{
26
25
return "" ;
27
26
}
28
-
29
- if (string .equalsIgnoreCase (" " ))
27
+ else if (string .equalsIgnoreCase (" " ))
28
+ {
29
+ return "" ;
30
+ }
31
+ else if (string .equalsIgnoreCase ("" ))
30
32
{
31
33
return "" ;
32
34
}
@@ -43,16 +45,58 @@ public static String replaceNull(String string)
43
45
**/
44
46
public static int replaceTrueOrFalse (String string )
45
47
{
46
- if (string .equalsIgnoreCase ("True" ))
48
+ return string .equalsIgnoreCase ("True" ) ? 1 : 0 ;
49
+ }
50
+
51
+ /**
52
+ * 2018 September 14 - Friday - 12:34 PM
53
+ * replace null with zero method
54
+ *
55
+ * this method will replace null or empty values of string with zero
56
+ *
57
+ * @param stringToReplace - string to replace null with
58
+ * @return it will return 1 or 0
59
+ **/
60
+ public static int replaceNullWithZero (String stringToReplace )
61
+ {
62
+ if (stringToReplace == null )
47
63
{
48
- return 1 ;
64
+ return 0 ;
49
65
}
50
-
51
- if (string .equalsIgnoreCase ("False" ))
66
+ else if (stringToReplace .equalsIgnoreCase ("null" ))
52
67
{
53
68
return 0 ;
54
69
}
70
+ else if (stringToReplace .equalsIgnoreCase (" " ))
71
+ {
72
+ return 0 ;
73
+ }
74
+ else if (stringToReplace .equalsIgnoreCase ("" ))
75
+ {
76
+ return 0 ;
77
+ }
78
+ else
79
+ {
80
+ return Integer .parseInt (stringToReplace );
81
+ }
82
+ }
83
+
84
+ /**
85
+ * 2018 September 14 - Friday - 12:34 PM
86
+ * remove last char method
87
+ *
88
+ * this method will remove the last character of the string
89
+ *
90
+ * @param stringToRemovedLastCharFrom - string to remove the last character from
91
+ * @return it will return string with last character removed
92
+ **/
93
+ public static String removeLastChar (String stringToRemovedLastCharFrom )
94
+ {
95
+ if (stringToRemovedLastCharFrom != null && stringToRemovedLastCharFrom .length () > 0 )
96
+ {
97
+ stringToRemovedLastCharFrom = stringToRemovedLastCharFrom .substring (0 , stringToRemovedLastCharFrom .length () - 1 );
98
+ }
55
99
56
- return 0 ;
100
+ return stringToRemovedLastCharFrom ;
57
101
}
58
102
}
0 commit comments