|
-
Jul 8th, 2010, 04:05 AM
#1
Thread Starter
Hyperactive Member
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.
-
Jul 8th, 2010, 07:46 AM
#2
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|