aspose file tools*
The moose likes Beginning Java and the fly likes String Split with Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Split with "\\t"" Watch "String Split with "\\t"" New topic
Author

String Split with "\\t"

Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 509

So I am getting text file from somewhere. According to her, the file data is tab delimited. But when I parse it with above code, it does not give expected output. I know that tab is actually editor specific, you can configure tab to 4 while other can set it to 8. But how does Java (above code) interprets it? Now as I have edited the file with setting proper tab on MY machine, it parses it perfectly and I am getting expected result.

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Saurabh Pillai wrote:
So I am getting text file from somewhere. According to her, the file data is tab delimited. But when I parse it with above code, it does not give expected output. I know that tab is actually editor specific, you can configure tab to 4 while other can set it to 8. But how does Java (above code) interprets it? Now as I have edited the file with setting proper tab on MY machine, it parses it perfectly and I am getting expected result.



The regex library parses "\\t" as a tab character -- meaning ASCII code 9. It doesn't do anything special such as treat spaces to a position as a tab, etc.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 509
Henry Wong wrote:The regex library parses "\\t" as a tab character -- meaning ASCII code 9. It doesn't do anything special such as treat spaces to a position as a tab, etc.

Henry

So as it does not parse the file properly, it is safe to conclude that actually the file is not tab delimited, right? Yes, I think so.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39435
    
  28
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 509
Yes the file is inconsistent with tabs, some fields are multi-tabs delimited while others are single tab delimited.

I think I need to start seeing the file as string of encoded characters

Thank you guys.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39435
    
  28
If they really are multiple tabs, you have two (or more) possible responses. You can request a new version of the file in the correct format, or change your regex slightly
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String Split with "\\t"