File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Split... multiple spaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Split... multiple spaces" Watch "Split... multiple spaces" New topic

Split... multiple spaces

madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148
Probably has been asked many times ,but since the group doesnt a search feature (or maybe it has and i dont know about it) i think my quickest way out is to post it.

I need to split a string "This is my Red house".
remember string contains multiple spaces like 3 before Red and 4 before house to the following


can someone show me the way out.
The String Tokenizer class dosent seem to have someting like this , i think String.split may have something but havent been able to find out..

Money for nothing and Java for Free
Peter Stibrany

Joined: Mar 04, 2005
Posts: 1

Using String.split is good way to do this.

You will get array consisting of "This", "is", "my", "Red", "house". That " +" argument to split method means that delimeter is one or more spaces (it is regular expression).
[ May 18, 2005: Message edited by: Peter Stibrany ]
madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148
Bulls Eye !!!
Thanks Mate... that solved my problem!!

Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
As an aside, see for several tips on how to search this site.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: Split... multiple spaces
It's not a secret anymore!