Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Removing spaces and tabs from string

807589Jul 29 2008 — edited Jul 31 2008
How can I remove spaces and tabs from begining of a string. I can't use
"                 Ab z m".replaceAll( "\\s+", "" ); //   
because It will remove all the spaces even between Ab , z and m.

What I really need is only to check if there is a space or tabs in the string I have to remove them. Note that I read the string from a file line by line, so each line is different from the other.

I tried this solution, but it did not work too because some times the string has no space or tabs in the begining.
String tabs = "Ab z m"; // it works well if tabs = "                  Ab z m"; 
String[] parts = tabs.split(" ", 2);		
System.out.println(parts[1]);
Thanks a lot
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 28 2008
Added on Jul 29 2008
4 comments
771 views