This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
 
Similar Threads
Stirng replacement seemingly simple but I couldnt find a simple way
removing newline and tabs from a string
How to Save from JTextArea using JFileChooser as a TXT file.
Undo pretty-Print
Scanner seeing "" as input with each loop