Results 1 to 14 of 14
Thread: Help with separator
- 09-19-2010, 07:39 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 36
- Rep Power
- 0
Help with separator
Hi, I would like to use separator but the results come out were not what I expected.
I use
Tos = To.split(",");
for (int i = 0; i < Tos.length; i++)
{
System.out.println(Tos[i]);
}
I was using printwriter as well. I hope that in the file the result should look like this:
To:ll
To:ooo
To:pp
Instead of
To:ll,ooo,pp
Is anyone know what's the problem?
- 09-19-2010, 08:09 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Please edit your post and use [code] ... [/code] tags instead of those smilies so we can actually read what you wrote; also show us your original String 'To'.
kind regards,
Jos
- 09-19-2010, 08:13 AM #3
Member
- Join Date
- Sep 2010
- Posts
- 36
- Rep Power
- 0
System.out.println("To who?");
To = in.nextLine();
Tos = To.split(",");
for (int i = 0; i < Tos.length; i++)
{
System.out.println(Tos[i]);
}
I hope that in the file the result should look like this:
To:ll
To:lpp
To:lii
Instead of
To:ll,lpp,lii
- 09-19-2010, 08:21 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
- 09-19-2010, 08:27 AM #5
Member
- Join Date
- Sep 2010
- Posts
- 36
- Rep Power
- 0
The code I use to print file is as below:
pwInput.println("To: " + To);
- 09-19-2010, 08:44 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
- 09-19-2010, 08:50 AM #7
Member
- Join Date
- Sep 2010
- Posts
- 36
- Rep Power
- 0
pwInput.println("To: " + To);
String delimiter = ",";
if (To.equals(",")) {
rr = To.split(delimiter);
for (int i = 0; i < rr.length; i++)
{
pwInput.println("To: " + rr[i]);
}}
This isn't work as well.
I actually want the output to be:
To:ll
To:lpp
To:lii
Instead of
To:ll,lpp,lii
- 09-19-2010, 08:57 AM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
- 09-19-2010, 09:02 AM #9
Member
- Join Date
- Sep 2010
- Posts
- 36
- Rep Power
- 0
So how do I make the printwriter to be the way I want if the string contains comma?
- 09-19-2010, 09:25 AM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Think a bit: if your String is equal to "a,b,c" you want to output to be:
If the String equals "a", do you want the output to be:Java Code:To: a To: b To: c
? If so, have a look at the String.split( ... ) method again, if not, please explain what you want.Java Code:To: a
kind regards,
Jos
- 09-19-2010, 09:46 AM #11
Member
- Join Date
- Sep 2010
- Posts
- 36
- Rep Power
- 0
My problem is the code
To: a
To: b
To: c
showed in the command window instead of showing in the printwriter.
I don't know why.
- 09-19-2010, 09:47 AM #12
Member
- Join Date
- Sep 2010
- Posts
- 36
- Rep Power
- 0
It shows in command window as:
To:a
To:b
To:c
but it shows in the file as:
To:a,b,c
- 09-19-2010, 10:07 AM #13
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
You are using the println( ... ) method when you print to the console but you are using print( ... ) when you're writing to a file; you should print an end-of-line character to the file as well for every line. And please show us the actual code you are using because as it is now the entire thread becomes confusing at best.
kind regards,
Jos
- 09-19-2010, 10:08 AM #14
Member
- Join Date
- Sep 2010
- Posts
- 36
- Rep Power
- 0
Similar Threads
-
Remove separator between windows
By Annie George in forum NetBeansReplies: 0Last Post: 09-09-2010, 09:04 AM -
Tip for System Defined line separator in a Batch File
By Java Tip in forum java.langReplies: 0Last Post: 04-04-2008, 02:48 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks