DR00ME Posted March 24, 2004 Posted March 24, 2004 (edited) Hello, I got this application which is writing stuff in a file....with .WriteLine.... after reading the file in the listbox with .ReadToEnd I noticed .WriteLine leaves a terminator (????) It causes major problems in my applicaiton when I tried to use 'if not listbox.items.contains' because the value got something garbage in the end (terminator?).... what should I do ? I dont want to leave any terminators in my file....tough when I edited the file with notepad there werent any marks of terminators.... but I saw some weird symbol in end of some of the listbox values as shown in the pic at the end... This is how I read the stuff from the file to a ListBox: (The values are separated with ';' in the file) Dim HSL_Array() As String Dim HSL_String As String Dim SR As StreamReader Dim FileHandle As File Dim i As Integer Dim ArraySplit As String Dim FilterListBox As New ListBox 'Read the stuff from the file in HSL_String If FileHandle.Exists("Calibration.ini") Then SR = FileHandle.OpenText("Calibration.ini") HSL_String = SR.ReadToEnd SR.Close() 'Separate the values with splitting the string in the HSL_Array HSL_Array = HSL_String.Split(";"c) 'Now write the array values in a listbox.... For i = 0 To HSL_Array.Length - 1 'ListBox1.Items.Add(HSL_Array(i)) 'testbox ArraySplit = HSL_Array(i) FilterListBox.Items.Add(ArraySplit) Next i 'Clear the HSL_Array because it is not needed anymore HSL_Array.Clear(HSL_Array, 0, HSL_Array.Length) End If And This is how I write in the file: Private Sub Calibrate() Dim i As Integer Dim dataString As String Dim fileDataString As String Dim FileHandle As File Dim SR As StreamReader Dim SW As StreamWriter 'Read the new stuff from the listbox in dataString For i = 0 To lstHSL1.Items.Count() - 1 If dataString = Nothing Then dataString = lstHSL1.Items(i) Else dataString = dataString + ";" + lstHSL1.Items(i) End If Next i 'Read the old stuff from the file into fileDataString If FileHandle.Exists("Calibration.ini") Then SR = FileHandle.OpenText("Calibration.ini") fileDataString = SR.ReadToEnd SR.Close() End If 'Write the old stuff (fileDataString) + the new stuff(dataString) in the file..... SW = FileHandle.CreateText("Calibration.ini") If fileDataString = Nothing Then SW.WriteLine(dataString) Else SW.WriteLine(fileDataString + ";" + dataString) End If SW.Close() End Sub Edited March 24, 2004 by DR00ME Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
DR00ME Posted March 24, 2004 Author Posted March 24, 2004 btw when the writing sequence ends that damn symbol comes there in the end of the stream....but from where ?????????? Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Leaders dynamic_sysop Posted March 24, 2004 Leaders Posted March 24, 2004 they are Return chars ( Environment.NewLine , or Chr ( 10 ) or Chr ( 13 ) or VbCrlf's ) Quote
Leaders dynamic_sysop Posted March 24, 2004 Leaders Posted March 24, 2004 btw , you would be better reading the StreamReader differently , try it like this ... While Not SR.Peek() = -1 FilterListBox.Items.Add(SR.ReadLine()) End While Quote
DR00ME Posted March 24, 2004 Author Posted March 24, 2004 you are amazing!! :D P.S. omg those return chars really pissed me off :) Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.