java - Removing spaces between letters and double spaces between words -
i need remove spaces between letters , make double spaces single spaces between words.
so (double spaces between words):
h e l l o m y n m e s b o b
will need become this:
hello name bob
i've tried
temp = "h e l l o m y n m e s b o b"
temp = temp.trim().replaceall("\\s", "");
removes spaces.
i managed make work doing:
temp = temp.replace(" ", ".");
temp = temp.replace(" ", "");
temp = temp.replace(".", " ");
simpler way of doing it.
you should use regex \s(?!\s). says space doesn't have space after it.
this used this:
temp = "h e l l o m y n m e s b o b"; temp = temp.replaceall("\\s(?!\\s)", ""); system.out.println(temp);
outputs: hello name bob
hope helps :)