Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

break  line into words

Thread view: 
puzzlecracker - 24 Jun 2006 01:14 GMT
I have line

word0, word1, word2, word3, word4, ................

I want to break it into array of words a[0]=word0, a[1]=word1, etc

I was trying to use split with reg expression, but with  no luck...

can someone suggest an easy approach. thx
Jeffrey Schwab - 24 Jun 2006 01:20 GMT
> I have line
>
[quoted text clipped - 5 lines]
>
> can someone suggest an easy approach. thx

public class Main {
    public static void main(String[] args) {
        String line = "word0, word1, word2, word3, word4";
        String[] a = line.split(",\\s*");
        System.out.println(a[0]);   // word0
        System.out.println(a[1]);   // word1
    }
}
Timo Stamm - 24 Jun 2006 02:36 GMT
puzzlecracker schrieb:
> I have line
>
[quoted text clipped - 5 lines]
>
> can someone suggest an easy approach. thx

See java.text.BreakIterator
John O'Conner - 24 Jun 2006 15:28 GMT
> puzzlecracker schrieb:
>> I have line
[quoted text clipped - 8 lines]
>
> See java.text.BreakIterator

If that proves too difficult for the original poster, I suggest they
look at String.split().

--
John O'Conner
Timo Stamm - 24 Jun 2006 16:42 GMT
John O'Conner schrieb:
>> puzzlecracker schrieb:
>>> I have line
[quoted text clipped - 11 lines]
> If that proves too difficult for the original poster, I suggest they
> look at String.split().

I think he already did:

| I was trying to use split with reg expression, but with  no luck...
Rob - 24 Jun 2006 16:42 GMT
> I have line
>
[quoted text clipped - 5 lines]
>
> can someone suggest an easy approach. thx

StringTokenizer


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.