How to separate words by using tab in Java ?

T

tobleron

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" ??
 
A

Andreas Leitgeb

tobleron said:
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];
 
K

King_Alex

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.

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top