Searched other questions couldn't find any results.
I've written a regex to delete the spaces from the beginning of the line, but I need to count them and have them at the beginning of the line?
scan.nextLine().replaceAll("\\s+", "").trim();
Above is the regex (it's in a while loop). I'm reading in the text in a while loop to check if there is more text and it works fine but I don't know how I can print an integer with the number of spaces removed.
If you want to count the white spaces at the beginning of a string:
String s = " 123456";
int count = s.indexOf(s.trim());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With