Hello. (Sorry for bad english) How to remove every " " front of the string. I need to remove this. Code (Text): String string = "Hello my name is bla bla."
No, it wouldn't, but the solution he posted also wouldn't work entirely. It'll end up replacing half of the spacing inside the string, so now you end up with half of the original amount. @OP There's no real way to do that with one line; unless you knew the amount of spaces beforehand, but then you wouldn't need to remove them. There are two ways I suggest you going about this. The easy one, use the one guys solution but loop it every time the original string isn't equal to the new string. The slightly harder but more efficient, iterate through the chars and ignore multiple spaces if a space character was the previous char, while placing them into some type of buffer to later build the string into.
Give me a second. I have a code snip-it that can accomplish this somewhere. EDIT: found it Code (Text): String test = "yes yes"; System.out.println(test); test = test.trim().replaceAll(" +", " "); System.out.println(test); Output: Code (Text): yes yes yes yes