aspose file tools*
The moose likes Beginning Java and the fly likes identifying white spaces 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 "identifying white spaces" Watch "identifying white spaces" New topic
Author

identifying white spaces

Desmond Lee
Greenhorn

Joined: Oct 03, 2001
Posts: 3
Hi there
I'm trying to parse a string which that has carriage returns as delimeters. To do this i'm using a StringTokenizer and use "\n" as a delimeter string.
however, there may be serveral returns (or newlines "\n") in a row and then the next token. Or there could be any combination of newlines, tabs, and spaces before the next string text that we want as our token.
So, my question: is there a way to identify any whitespaces (by whitespace i mean any thing other than text ie. newlines, tables, spaces) using a certain escape sequence. For example, "\n" identifies a newline but is there something like "\w" that would take care off all whitespacing including newlines, tabs and spaces?
Thanks
Regards
Desmond Lee
Rowan Brownlee
Ranch Hand

Joined: Aug 07, 2000
Posts: 97
Hi Desmond,
I'm aware of the static Character methods isSpaceChar() and isWhiteSpace(), but I don't know of an escape sequence that would filter out non-text characters.
I wonder if you might need to use StreamTokenizer. It allows you to identify number, word (including single letter), end of line and end of file. You could for example use a switch statement based on the token, to identify numbers, words, end of line, end of file, and use a default to label everything else as spaces, tabs etc.
This way, you'd get all of your strings, characters, numbers and the rest wouldn't matter. It would however mean that single characters such as "$", "%" etc would end up in the default case.
If this sounds related to what you're after, let me know, as I have an example in code.
cheerio
rowan
Desmond Lee
Greenhorn

Joined: Oct 03, 2001
Posts: 3
Hi Rowan
If you could put up the example that would be awesome....
Thanks for you help
Regards
Desmond
Rowan Brownlee
Ranch Hand

Joined: Aug 07, 2000
Posts: 97
righto - eg. follows...


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: identifying white spaces