This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Split... multiple spaces

 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Peter Stibrany
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bulls Eye !!!
Thanks Mate... that solved my problem!!

ADIOS
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As an aside, see http://faq.javaranch.com/view?SearchFirst for several tips on how to search this site.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic