Results 1 to 4 of 4

Thread: displaying linenumber

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2013
    Posts
    25

    displaying linenumber

    I am writing a program that reads a file and then displays the words in a listbox. What I am having trouble with is that I need to also display the line that the word was on in the file. Could someone please push me in the right direction for this.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: displaying linenumber

    try this:

    Code:
    Imports System.Text.RegularExpressions
    
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim lines() As String = IO.File.ReadAllLines("filename.txt")
            For x As Integer = 0 To lines.GetUpperBound(0)
                For Each m As Match In New Regex("\b\w+\b").Matches(lines(x))
                    ListBox1.Items.Add(String.Format("{0}: {1}", x, m.Value))
                Next
            Next
        End Sub
    
    End Class

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2013
    Posts
    25

    Re: displaying linenumber

    I think I figured that part out but maybe you can help me with something else. I read the file and did all that I was supposed to and then I wrote that to another text file but now I can't figure out how to save that file with the same name as the one I read with the word "Concordance" appended to the front of it. Thank you for helping me so far.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: displaying linenumber

    Code:
    dim filename as string = "filename.txt"
    dim path as string = "c:\test"
    dim combinedPath1 as string = io.path.combine(path, filename) ' =  "c:\test\filename.txt"
    dim combinedPath2 as string = io.path.combine(path, "Concordance" & filename) ' =  "c:\test\Concordancefilename.txt"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width