aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Split... multiple spaces" Watch "Split... multiple spaces" New topic
Author

Split... multiple spaces

madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148
Hi,
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

This
is
my
Red
house

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
SCJP, SCWCD
Peter Stibrany
Greenhorn

Joined: Mar 04, 2005
Posts: 1
Hello.

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!!

ADIOS
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
As an aside, see http://faq.javaranch.com/view?SearchFirst 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
 
wood burning stoves
 
subject: Split... multiple spaces