Join 307,008 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,034 people online right now. Registration is fast and FREE... Join Now!
Hey guys, I am writing an array in a file with this loop.
CODE
sw.WriteLine("attributes")
For i = 0 To noatts - 1 sw.WriteLine(attName(i)) Next
This is creating weird results though.
Instead of: attributes att1 att2 att3
I am getting: attributes att1
att2
att3 (Notice the empty lines).
Anyone know why could that be? In other parts of the file writeline works well. It only creates extra lines on that specific section.
Btw: the file looks good if viewing by notepad, the extra lines appear when viewing in wordpad. Apparently that matters because when I reuse that file to read some values in my program, it crashes cause it reads those empty lines instead of the attributes.
This post has been edited by trashr0x: 7 Nov, 2009 - 09:01 AM
Are you reading in a new line character and putting it in attName? If you are reading in the new line character from a file and putting it in the attName, you would be writing the new line character and then WriteLine would append another.
Hey guys, I am writing an array in a file with this loop.
CODE
sw.WriteLine("attributes")
For i = 0 To noatts - 1 sw.WriteLine(attName(i)) Next
This is creating weird results though.
Instead of: attributes att1 att2 att3
I am getting: attributes att1
att2
att3 (Notice the empty lines).
Anyone know why could that be? In other parts of the file writeline works well. It only creates extra lines on that specific section.
Btw: the file looks good if viewing by notepad, the extra lines appear when viewing in wordpad. Apparently that matters because when I reuse that file to read some values in my program, it crashes cause it reads those empty lines instead of the attributes.
How are you filling attName(i)? Does it have CRLF at the end of it?
Are you reading in a new line character and putting it in attName? If you are reading in the new line character from a file and putting it in the attName, you would be writing the new line character and then WriteLine would append another.
I am writing the attname array in a file. One element per line.
Your problem is with the line txtAtt.Text.Split(vbCrLf)(k). If your token you are splitting on is at the end of the string, like the vbCrlf is at the end of the line, and you split it, it creates an empty piece at the end. You are adding that into your attNames array which is why you see the empty spaces. You are actually printing an empty token with a crlf on the end of it.
Your problem is with the line txtAtt.Text.Split(vbCrLf)(k). If your token you are splitting on is at the end of the string, like the vbCrlf is at the end of the line, and you split it, it creates an empty piece at the end. You are adding that into your attNames array which is why you see the empty spaces. You are actually printing an empty token with a crlf on the end of it.
Thats exactly what I was going to check when he uploaded the file, beat me to it lol.
Your problem is with the line txtAtt.Text.Split(vbCrLf)(k). If your token you are splitting on is at the end of the string, like the vbCrlf is at the end of the line, and you split it, it creates an empty piece at the end. You are adding that into your attNames array which is why you see the empty spaces. You are actually printing an empty token with a crlf on the end of it.
So are you telling me that the error happening is.. attname(1) = blabla attname(2) = empty attname(3) = blabla attname(4) = empty?
Your problem is with the line txtAtt.Text.Split(vbCrLf)(k). If your token you are splitting on is at the end of the string, like the vbCrlf is at the end of the line, and you split it, it creates an empty piece at the end. You are adding that into your attNames array which is why you see the empty spaces. You are actually printing an empty token with a crlf on the end of it.
So are you telling me that the error happening is.. attname(1) = blabla attname(2) = empty attname(3) = blabla attname(4) = empty?
No you are getting attname(1) = blabla{empty} attname(2) = blabla{empty}
from what I understand
This post has been edited by nmgod: 7 Nov, 2009 - 10:07 AM