Skip to content

Instantly share code, notes, and snippets.

@mksantoki
Last active February 14, 2019 06:20
Show Gist options
  • Save mksantoki/b7133712a44d2b148eabc4659a5fb4b2 to your computer and use it in GitHub Desktop.
Save mksantoki/b7133712a44d2b148eabc4659a5fb4b2 to your computer and use it in GitHub Desktop.
Android Remove zero from stating in string
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