• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String's split()

 
Chris Cairns
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Any help would be appreciated.
My question concerns the split method in the String class.
Let's pretend I have a sequence of Strings in a text file that are tabbed delimited. And some of the Strings are simply empty but are still delimited by a tab. For example, Hello [tab] how [tab] [tab] you [tab] ? (Obviously this person is a foreigner with bad grammar and forgot "are".) After reading this line in and converting it to a String object, I use the split method. My question is this: how does the split method handle the blank/empty string? What character data does it return? Because when I try to print the bytes of this, no bytes are printed.
I have some follow up questions, but I'll wait for some answsers first.

Thanks!
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the code that did not work?
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris, the split method returns an empty String. This probably means that no bytes are associated with the byte array within the String ( getBytes() returns a "new byte[0]" )
Jamie
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to try split("\t+"). This will treat multiple consecutive tabs as a single delimiter, and so the blank field will be skipped entirely. IF that's what you really want - quite possibly, it's not.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic