This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes String Split or StringTokenizer and Tabs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Split or StringTokenizer and Tabs" Watch "String Split or StringTokenizer and Tabs" New topic
Author

String Split or StringTokenizer and Tabs

Hosh Nasi
Ranch Hand

Joined: Sep 10, 2004
Posts: 44
I need to parse strings from a TDF filethat contains fields of sentences.. example



Up until recently I had just put an underscore in the all spaces. However I want it to work right without that workaround. First is it possible to only token by tabs? if so how? This is what I have been trying.



thanks guys!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
That looks like the right thing to try, all right. Did it get confused on spaces and split on them, too?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Hosh Nasi
Ranch Hand

Joined: Sep 10, 2004
Posts: 44
Yes stan for some reason I believe '\\t' is also spliting whitespace. I would think there would be a tab object. However.. No luck.
S. Lohi
Greenhorn

Joined: May 21, 2004
Posts: 11
Edit: I take that back, I remembered wrong

However, I still haven't had any problems with split("\\t") and whitespaces...
[ May 20, 2005: Message edited by: S. Lohi ]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

I'm not having any problems with this.

Try this simple test:



Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Originally posted by S. Lohi:
Using just "\t" has always worked for me (note only one backslash, I don't know why you have two of 'em).


Normally, you need two backslashes in order to pass the string consisting of the '\' and the 't' characters to the regex expression. However, in this case, passing the string consisting of the \u0009 character should work equally well, since the java compiler and the regex parser interpret \t as the same character.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Originally posted by S. Lohi:
Edit: I take that back, I remembered wrong


That's OK, using "\t" does in fact work just as well as "\\t" in this case.
 
GeeCON Prague 2014
 
subject: String Split or StringTokenizer and Tabs