Monday, January 9, 2012

Remove multiple spaces in a String

How to remove multiple spaces inside a String and just leave single space.

Eg: Input: "java          on    java"
      Output: "java on java"


Answer:
In Java, there is function replaceAll, we can simply use that as below, In C this was a bit cumbersome to do, but as they say, Java is Java. We can do it easy here.







No comments:

Post a Comment