Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Regular Expressions
I have been really struggling with regular expressions, can anyone tell
me how I would split up a string around the spaces and newlines.
Basically I want every word to be put into a string array but not the
spaces (which is what I am getting now).

--
Eps

Report this thread to moderator Post Follow-up to this message
Old Post
burchill
12-21-04 01:58 AM


Re: Regular Expressions
burchill wrote:
> I have been really struggling with regular expressions, can anyone tell
> me how I would split up a string around the spaces and newlines.
> Basically I want every word to be put into a string array but not the
> spaces (which is what I am getting now).
>
> --
> Eps

Sounds like you need to use the StringTokeniser class

Report this thread to moderator Post Follow-up to this message
Old Post
Andrew McDonagh
12-21-04 01:58 AM


Re: Regular Expressions
You might also look at the split method


Report this thread to moderator Post Follow-up to this message
Old Post
klynn47@comcast.net
12-21-04 01:58 AM


Re: Regular Expressions
Also you can collapse white space to a single space first.

string.replaceAll("\\s+"," ").split(" ")
This will return a String array of the tokens


Report this thread to moderator Post Follow-up to this message
Old Post
klynn47@comcast.net
12-21-04 01:58 AM


Re: Regular Expressions
"Andrew McDonagh" <news@andrewcdonagh.f2s.com> wrote in message
news:cq7bop$fa1$1@news.freedom2surf.net...
> burchill wrote: 
>
> Sounds like you need to use the StringTokeniser class
Not the best advice. From the docs:
"StringTokenizer is a legacy class that is retained for compatibility
reasons although its use is discouraged in new code. It is recommended that
anyone sing this functionality use the split method of String or the
java.util.regex package instead."

See my other post.



Report this thread to moderator Post Follow-up to this message
Old Post
Ryan Stewart
12-21-04 01:58 AM


Re: Regular Expressions
<klynn47@comcast.net> wrote in message
news:1103576113.209705.255230@f14g2000cwb.googlegroups.com...
> Also you can collapse white space to a single space first.
>
> string.replaceAll("\\s+"," ").split(" ")
> This will return a String array of the tokens
>
Why add the extra step?
string.split("\\s+");



Report this thread to moderator Post Follow-up to this message
Old Post
Ryan Stewart
12-21-04 01:58 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:57 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.