Skip to content

Commit e3de7f0

Browse files
committed
1. Added new method for removing last char from string and replacing null or empty value with 0.
2. Renamed replaceNull method to replaceNullWithEmpty
1 parent 2a5bc48 commit e3de7f0

File tree

1 file changed

+55
-11
lines changed

1 file changed

+55
-11
lines changed

app/src/main/java/com/amit/utilities/TextUtilities.java

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Created By AMIT JANGID
55
* 2018 April 17 - Tuesday - 12:52 PM
66
**/
7-
7+
@SuppressWarnings("unused")
88
public class TextUtilities
99
{
1010
/**
@@ -14,19 +14,21 @@ public class TextUtilities
1414
* @param string - string where you want to replace null
1515
* @return it will return empty string
1616
**/
17-
public static String replaceNull(String string)
17+
public static String replaceNullWithEmpty(String string)
1818
{
1919
if (string == null)
2020
{
2121
return "";
2222
}
23-
24-
if (string.equalsIgnoreCase("null"))
23+
else if (string.equalsIgnoreCase("null"))
2524
{
2625
return "";
2726
}
28-
29-
if (string.equalsIgnoreCase(" "))
27+
else if (string.equalsIgnoreCase(" "))
28+
{
29+
return "";
30+
}
31+
else if (string.equalsIgnoreCase(""))
3032
{
3133
return "";
3234
}
@@ -43,16 +45,58 @@ public static String replaceNull(String string)
4345
**/
4446
public static int replaceTrueOrFalse(String string)
4547
{
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)
4763
{
48-
return 1;
64+
return 0;
4965
}
50-
51-
if (string.equalsIgnoreCase("False"))
66+
else if (stringToReplace.equalsIgnoreCase("null"))
5267
{
5368
return 0;
5469
}
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+
}
5599

56-
return 0;
100+
return stringToRemovedLastCharFrom;
57101
}
58102
}

0 commit comments

Comments
 (0)