Last active
February 14, 2019 06:20
-
-
Save mksantoki/b7133712a44d2b148eabc4659a5fb4b2 to your computer and use it in GitHub Desktop.
Android Remove zero from stating in string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String removeZero(String str) | |
{ | |
// Count leading zeros | |
int i = 0; | |
while (str.charAt(i) == '0') | |
i++; | |
// Convert str into StringBuffer as Strings | |
// are immutable. | |
StringBuffer sb = new StringBuffer(str); | |
// The StringBuffer replace function removes | |
// i characters from given index (0 here) | |
sb.replace(0, i, ""); | |
return sb.toString(); // return in String | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment