akim Posted July 6, 2003 Posted July 6, 2003 hi, i want to search a file for a specific number. the number is 10 positions after the word PPI in the textfile. when the number is found, i want to take the number and compare it to the another number. can anyone give me an example??????? thx akim123 Quote
Leaders dynamic_sysop Posted July 6, 2003 Leaders Posted July 6, 2003 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim sr As IO.StreamReader = New IO.StreamReader(New IO.FileStream("C:\test.txt", IO.FileMode.Open)) Dim i As Integer, s As String, c As Char s = sr.ReadToEnd If InStr(s, "PPI", CompareMethod.Text) Then i = InStr(s, "PPI", CompareMethod.Text) c = Mid(s, i + 10) '/// get the char 10 places after PPI '/// do your stuff to compare numbers , eg: Select Case c Case "7" MessageBox.Show("the numbers match!") Case Else MessageBox.Show("the numbers are different!") End Select End If sr.Close() End Sub hope this helps :) Quote
akim Posted July 6, 2003 Author Posted July 6, 2003 hi, first af all , thanx for your great example!!!!!!!!! now i have the problems that i want to have not only position 10 after the word PPI , i want to have the numbers 10 - 15 after ppi. can you help me?? thanx alot akim123 Quote
*Experts* mutant Posted July 6, 2003 *Experts* Posted July 6, 2003 Dim reader As New IO.StreamReader("pathtofile") Dim filetext As String = reader.ReadToEnd() Dim ppistart As Integer = filetext.IndexOf("PPI") + 3 'add 3 becuase 'the word is 3 letter long so we get the number right after the word Dim numbers() As Char = filetext.Substring(ppistart + 10, 5) 'start at 10 positions after "PPI" was found, and get next 5 characters reader.Close() The numbers() array will now contain all the 5 numbers 10-15. You should use those methods of the string instead of the ones dynamic_sysop showed you. Quote
akim Posted July 6, 2003 Author Posted July 6, 2003 thx alot for your example. it really helped me out. with your example i got the value i want into numbers. but it is of type char. i can't say dim i,s as integer i = 200 s = i + numbers. can you help me thx akim Quote
*Experts* mutant Posted July 6, 2003 *Experts* Posted July 6, 2003 Change the declaration of numbers() to: Dim numbers As String = filetext.Substring(ppistart + 10, 5) 'then convert the string to a number Convert.ToInt32(numbers) Then convert the string to a number. Quote
akim Posted July 6, 2003 Author Posted July 6, 2003 Hi, thx for your example. ok, i made it like th is: dim numbers as double = filetext.Substring(ppistart + 10, 5) it works. but the value in my textfile is for example 23.5332 it should be a double value. when i see the output of numbers it gives me 235332 it must be 23,5332. --> a double value in the end . can you help me??????? thx akim Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.