I am trying to parse a line something like this:
Entrance "20:00" - the output will be "20" Input "02:30" - the output will be "2" Input "00:30" - the output will be "".
This is how I wrote, I donβt like the way I do it, looking for a more efficient way to do this can be in one scan. Any ideas?
private String getString(final String inputString) { String inputString = "20:00"; // This is just for example final String[] splittedString = inputString.split(":"); final String firstString = splittedString[0]; int i; for (i = 0; i < firstString.length(); i++) { if (firstString.charAt(i) != '0') { break; } } String outputString = ""; if (i != firstString.length()) { outputString = firstString.substring(i, firstString.length()); } return outputString; }
Rishi source share