Hello !
I just downloaded a Dictionary Words list .txt( containing all dictionary words ), every word is on a line.
What i need is only words > 5 letters ( length > 5 ). S o i though about making a Visual basic software that delete words < 5 letters from the file.

This is how i read a file from VB

Dim FILE_NAME As String = "C:\Users\Owner\Documents\test.txt"
Dim TextLine As String

If System.IO.File.Exists(FILE_NAME) = True Then

Dim objReader As New System.IO.StreamReader(FILE_NAME)

Do While objReader.Peek() <> -1
TextLine = TextLine & objReader.ReadLine() & vbNewLine
Loop

Textbox1.Text = TextLine

Else

MsgBox("File Does Not Exist")

End If

Any WAy could you help me with the code ? How to delete the word smaller then 5 letters ?

I am using Visual basic 2008
And Visual Basic language
The list is in .txt format

Thanks :)

I think something like that is more suited to vbScript than VB. The following script takes 2 arguments, infile and outfile. Infile contains the unfiltered dictionary (one word per line). Outfile is the file to contain the filtered words (will be created if it does not exist). Here is the code

Const ForReading   = 1
Const ForWriting   = 2
Const ForAppending = 8

set fso = CreateObject("Scripting.FileSystemObject")
set arg = Wscript.Arguments

if arg.Count <> 2 Then
   wscript.Echo "delete5 infile outfile"
   wscript.Quit
end if

if Not fso.FileExists(arg(0)) then
   wscript.Echo "file",arg(0),"not found"
   wscript.Quit
end if

set tsoin  = fso.OpenTextFile(arg(0),ForReading)
set tsoout = fso.OpenTextFile(arg(1),ForWriting,True)

do until tsoin.AtEndOfStream

   line = Trim(tsoin.ReadLine)
   
   if Len(line) > 5 Then
      tsoout.WriteLine(line)
   end if
   
loop

tsoin.Close()
tsoout.Close()

Also you can modify slightly your code to not include the short lines like:

Dim FILE_NAME As String = "C:\Users\Owner\Documents\test.txt"
Dim TextLine As String

If System.IO.File.Exists(FILE_NAME) = True Then

    Dim objReader As New System.IO.StreamReader(FILE_NAME)

    Do While objReader.Peek() <> -1
        '
        ' Red a line
        '
        Dim CurLine as String = objReader.ReadLine().Trim() 
        '
        '  Add it only if length > 5 
        '
        if Curline.Length > 5 then TextLine = TextLine & Curline & vbNewLine
    Loop

    Textbox1.Text = TextLine

Else

    MsgBox("File Does Not Exist")

End If

That is only another way.
Hope this helps

Also you can modify slightly your code to not include the short lines like:

Dim FILE_NAME As String = "C:\Users\Owner\Documents\test.txt"
Dim TextLine As String

If System.IO.File.Exists(FILE_NAME) = True Then

    Dim objReader As New System.IO.StreamReader(FILE_NAME)

    Do While objReader.Peek() <> -1
        '
        ' Red a line
        '
        Dim CurLine as String = objReader.ReadLine().Trim() 
        '
        '  Add it only if length > 5 
        '
        if Curline.Length > 5 then TextLine = TextLine & Curline & vbNewLine
    Loop

    Textbox1.Text = TextLine

Else

    MsgBox("File Does Not Exist")

End If

That is only another way.
Hope this helps

Nice code. Just out of curiosity, in this case, does Visual Basic starts counting the lenght of the line at 0 or it starts at 1. Just curious.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.