aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Clipboard/Tokenizer -- copy and paste problem 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 » Swing / AWT / SWT
Bookmark "Clipboard/Tokenizer -- copy and paste problem" Watch "Clipboard/Tokenizer -- copy and paste problem" New topic
Author

Clipboard/Tokenizer -- copy and paste problem

Sam Kebab
Ranch Hand

Joined: Jan 23, 2002
Posts: 104
Hello.
I have a jtable that has the capacity for copy and paste to an excel spreadsheet -- using a clipboard etc.
My problem is 1) when pasting to the jtable from excel, the StringTokenizer skips any blank new line.
For e.g. : in excel i copy these (1 column 3 rows)
545646
<blank space here>
545648
The result after pasting it on my table:
545646
545648
note: the blank space is gone -- and that is my problem. i need to copy it as it was in excel.
i.e. how do i keep the blank space when i paste on my jtable; the tokenizer just skips all blank spaces. i've tried the delimeters \n, \t, etc.
Thanks in advance for your help.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
I can't duplicate your problem.
StringTokenizer is handling spaces and new lines just fine for me. This code is how I tested it:

Maybe if you were to post some code...
Good Luck.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Originally posted by Shawarma Kebab:
the tokenizer just skips all blank spaces. i've tried the delimeters \n, \t, etc.

Maybe you are misusing the StringTokenizer. If a blank space or new line character ('\n') is one of your specified delimiters, then that character is not displayed, rather it is the delimiter and the text elements around it are the String objects returned by nextToken().
So, if my String were:
String string = "Hello, Fred. How are you doing?";
and my StringTokenizer were:
StringTokenizer stk = new StringTokenizer(string, ", .?");
then I'd be checking for four delimiters:
"," - comma
" " - space
"." - period
"?" - question mark
and this:
while (stk.hasMoreTokens()) {
System.out.println(stk.nextToken());
}
would print:
Hello
Fred
How
are
you
doing
Making sense?
[ March 12, 2002: Message edited by: Dirk Schreckmann ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
And removing the space from the delimiter list such that:
StringTokenizer stk = new StringTokenizer(string, ",.?");
means that were are using only three delimiters and the resulting output of the above code would be:

But perhaps all of this was not related to your problem...
Sam Kebab
Ranch Hand

Joined: Jan 23, 2002
Posts: 104
Thanks for your input Dirk.
The problem was actually dealing with two consecutive \n\n (i.e. two line feeds). I needed to erase the second line feed and keep the first line feed, whenever \n\n was found.
Thanks man.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Clipboard/Tokenizer -- copy and paste problem