I’m reading the contents of a text file and putting each line into a listbox. I’m trying to make it not put the text “WORKSTATION” into the listbox if that text is detected. I’ve tried a few variations of the following code, but the results are always the same. It finds “WORKSTATION” in the file, but still puts it into the list box. What am I doing wrong? Everything else is working fine, it just doesn’t skip the “WORKSTATION” text when it finds it.
Dim vendors As FolderItem = SpecialFolder.Temporary.child("WK_Vend.txt")
Dim t as TextInputStream
dim A as integer = 0
while A = 0
if vendors.Exists then
t = TextInputStream.Open(vendors)
t.Encoding = Encodings.UTF16
dim x as string
While Not t.EndOfFile
x = t.ReadLine
if x <> "WORKSTATION" then
VENDORS_LISTBOX.addrow(x)
end
Wend
t.Close
vendors.Delete
A = A + 1
end
wend
// ...
var contents as string = t.ReadAll
t.Close
contents = contents.ConvertEncoding( Encodings.UTF8 )
contents = contents.ReplaceLineEndings( &uA )
var lines() as string = contents.Split( &uA )
for each line as string in lines
if line.IndexOf( "WORKSTATION" ) = -1 then
VENDORS_LISTBOX.AddRow( line )
end
next line
// ...
VENDOR_LOOKUP.PushButton1.Action, line 67
This item does not exist
if line.IndexOf( “WORKSTATION” ) = -1 then
and
VENDOR_LOOKUP.PushButton1.Action, line 67
There is more than one method with this name but this does not match any of the available signatures.
if line.IndexOf( “WORKSTATION” ) = -1 then
var s as string
s = "1" + EndOfLine.CRLF + "2" + EndOfLine.CRLF
var t as FolderItem = FolderItem.TemporaryFile
var b as BinaryStream = BinaryStream.Open( t, true )
b.Write s
b.Close
b = nil
var tis as TextInputStream = TextInputStream.Open( t )
tis.Encoding = Encodings.UTF8
var contents as string = tis.ReadAll
tis.Close
t.Remove
return
Edit: I set a breakpoint at the return to check the contents through the debugger.
The point of the test is to see if a file created with different line endings would automatically convert to the ones used by the current platform. EndOfLine always returns the current platform’s line endings.