How to separate words by using tab in Java ?

Discussion in 'Java' started by tobleron, Oct 21, 2008.

  1. tobleron

    tobleron Guest

    Hi, I have a data like this :

    String sample = "blaa blee bliii bloo bluu";

    These words were separated by tab (not space). I want to classify them
    into :

    String word1 = "blaa";
    String word2 = "blee";
    String word3 = "blii";
    String word4 = "bloo";
    String word5 = "bluu";

    How to do that ? Please help. Thank you in advance.

    Note : I know how to use scanner. I also know that new line is "\n".
    But I don't know about tab. Is it "\t" ??
     
    tobleron, Oct 21, 2008
    #1
    1. Advertising

  2. tobleron <> wrote:
    > Hi, I have a data like this :
    > String sample = "blaa blee bliii bloo bluu";
    > These words were separated by tab (not space).
    > I want to classify them into :
    > String word1 = "blaa";
    > String word2 = "blee";
    > String word3 = "blii";
    > String word4 = "bloo";
    > String word5 = "bluu";


    > How to do that ? Please help. Thank you in advance.
    > Note : I know how to use scanner. I also know that new line is "\n".
    > But I don't know about tab. Is it "\t" ??


    Yes, it is, (as can be seen by following one of the many links
    to "Pattern" from Scanner's javadoc, and reading there.)

    Another, perhaps simpler option for you could be using String.split:
    String[] words = sample.split("\t");
    now: words[0]=="blaa", words[1]=="blee", ...

    finally, if really necessary, assign to separate variables:
    String word1=words[0], ... , word5=words[4];
     
    Andreas Leitgeb, Oct 21, 2008
    #2
    1. Advertising

  3. tobleron

    tobleron Guest

    @lew and Andreas,

    Thank you for your help. It works now.
     
    tobleron, Oct 21, 2008
    #3
  4. tobleron

    FrenKy Guest

    Lew wrote:
    > tobleron wrote:
    >> Hi, I have a data like this :
    >>
    >> String sample = "blaa blee bliii bloo bluu";
    >>
    >> These words were separated by tab (not space). I want to classify them
    >> into :
    >>
    >> String word1 = "blaa";
    >> String word2 = "blee";
    >> String word3 = "blii";
    >> String word4 = "bloo";
    >> String word5 = "bluu";
    >>
    >> How to do that ? Please help. Thank you in advance.
    >>
    >> Note : I know how to use scanner. I also know that new line is "\n".
    >> But I don't know about tab. Is it "\t" ??

    >
    > <http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.6>
    >
    > One minute of research. JLSIYF.
    >
    > Read the Java tutorial(s):
    > <http://java.sun.com/developer/onlineTraining/>
    >


    JLSIYF??? What is that... Google does not know :(
    Java Language Specification In Your Face???
     
    FrenKy, Oct 21, 2008
    #4
  5. tobleron

    King_Alex Guest

    On Oct 22, 4:48 am, Lew <> wrote:
    > Lew wrote:
    > >> <http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.....>

    >
    > >> One minute of research.  JLSIYF.

    > FrenKy wrote:
    > > JLSIYF??? What is that... Google does not know :(
    > > Java Language Specification In Your Face???

    >
    > Oh, come on.  Really?
    >
    > You got the JLS part.  Now relate the rest to "GIYF" and it should all come clear.
    >
    > One question mark is sufficient to indicate an interrogative.
    >
    > --
    > Lew


    I didn't get it... can you help?

    ===================================
    Meet all Java developers, join the community, help the developers who
    are new to Java www.techcubetalk.com
    ===================================
     
    King_Alex, Oct 22, 2008
    #5
  6. King_Alex wrote:
    > On Oct 22, 4:48 am, Lew <> wrote:
    >> Lew wrote:
    >>>> <http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3....>
    >>>> One minute of research. JLSIYF.

    >> FrenKy wrote:
    >>> JLSIYF??? What is that... Google does not know :(
    >>> Java Language Specification In Your Face???

    >> Oh, come on. Really?
    >>
    >> You got the JLS part. Now relate the rest to "GIYF" and it should all come clear.
    >>
    >> One question mark is sufficient to indicate an interrogative.
    >>
    >> --
    >> Lew

    >
    > I didn't get it... can you help?
    >


    http://www.google.com/search?q=GIYF

    --
    RGB
     
    RedGrittyBrick, Oct 22, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. EvgueniB
    Replies:
    1
    Views:
    632
    Anthony Borla
    Dec 15, 2003
  2. Virgo
    Replies:
    3
    Views:
    5,012
    Karl Heinz Buchegger
    Jan 27, 2004
  3. Frank Fredstone
    Replies:
    1
    Views:
    442
    Jean-Francois Briere
    Jun 27, 2006
  4. Eric

    Separate two words

    Eric, Aug 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    364
    Bruno Alexandre
    Aug 9, 2006
  5. KK
    Replies:
    5
    Views:
    529
    Arne Vajhøj
    Jul 12, 2008
Loading...

Share This Page