Results 1 to 2 of 2

Thread: Won't show all integers in string, please help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Location
    England
    Posts
    270

    Won't show all integers in string, please help

    I have a code where I search a text file for for example: "2320018200000", then it looks it up and finds a line like this:
    "3 1604001Sf nyretalg 20 kgs frys00031000100142Test før: 00365001800009000000000000000000000000010000000Sf nyretalg 20 kgs frys0000000 2320018200000"

    I want it to put that entire line in a label, but for some reason it skips the "3 1604001Sf" in the start. Here's my code:

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim test = FindStringInFile("C:\Users\danl.FATLAND\Documents\vare.txt", TextBox1.Text)
            If test Then
                Dim cnstart = TextBox1.Text
                Dim lines = IO.File.ReadAllLines("C:\Users\danl.FATLAND\Documents\vare.txt")
                Dim ComputerName = (From firstline In lines Where firstline.Contains(cnstart)).First.Substring(cnstart.Length)
                Label2.Text = ComputerName
    
            Else
                MessageBox.Show("not found")
            End If
    
    
        End Sub
    
    
        Public Function FindStringInFile(ByVal Filename As String, ByVal SearchString As String) As Boolean
            Dim Reader As System.IO.StreamReader
            Reader = New IO.StreamReader(Filename)
            Dim readalllines As String
            Try
                While Reader.Peek <> -1
                    readalllines = Reader.ReadToEnd()
                    If InStr(readalllines, SearchString) > 0 Then Return True
                End While
                Reader.Close()
                Return False
            Catch ex As Exception
                MessageBox.Show("Exception: " & ex.Message)
                Return False
            End Try
        End Function
    Thanks in advance for your time.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Won't show all integers in string, please help

    It's doing exactly what you're telling it to do.
    Code:
    .Substring(cnstart.Length)
    If you want the whole string then why are you telling it to get a substring?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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