I have txt file (xdos.txt) and this is its contents:
-----------------------------------------------------------
Pinging yahoo.com [98.139.183.24] with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Reply from 98.139.183.24: bytes=32 time=251ms TTL=51
Ping statistics for 98.139.183.24:
Packets: Sent = 4, Received = 1, Lost = 3 (75% loss),
Approximate round trip times in milli-seconds:
Minimum = 251ms, Maximum = 251ms, Average = 251ms
------------------------------------------------------------
I want to read only "from 98.139.183.24" from the file and put them in textbox1.text
Read Specific words from txt file
Page 1 of 14 Replies - 551 Views - Last Post: 06 October 2012 - 07:25 AM
Replies To: Read Specific words from txt file
#2
Re: Read Specific words from txt file
Posted 05 October 2012 - 03:38 PM
Have a look at SubString, Contains, and IndexOf, all of which are methods of the String class.
Let us know if you need more hints.
Let us know if you need more hints.
#3
Re: Read Specific words from txt file
Posted 05 October 2012 - 03:41 PM
does the .txt file always contain this structure ?
why dont you read one line at time at the correct position add this to a text box
kevin
why dont you read one line at time at the correct position add this to a text box
kevin
#4
Re: Read Specific words from txt file
Posted 05 October 2012 - 11:17 PM
Using Regex class (don't forget to import System.Text.RegularExpressions namespace) will really do the work for you.
You can do it the way lar3ry mentioned, but learning regular expressions will save you a lot of time in similar situations. Instead of counting how many characters you need to subtract from string (and substring), and writing method to do all this, you simply match your string with given pattern:
Dim extractedTextResults As MatchCollection = Regex.Matches(myTestString, "(?<=Reply )(.*?)(?=: bytes)")
where myTestString is your text, from where you want the results matching everything between "Reply " and ": bytes", excluding those two. What is left is "from XX.XXX.XXX.XX" in your case (XX represents any IP).
You than iterate through this MatchCollection. For example:
You can do it the way lar3ry mentioned, but learning regular expressions will save you a lot of time in similar situations. Instead of counting how many characters you need to subtract from string (and substring), and writing method to do all this, you simply match your string with given pattern:
Dim extractedTextResults As MatchCollection = Regex.Matches(myTestString, "(?<=Reply )(.*?)(?=: bytes)")
where myTestString is your text, from where you want the results matching everything between "Reply " and ": bytes", excluding those two. What is left is "from XX.XXX.XXX.XX" in your case (XX represents any IP).
You than iterate through this MatchCollection. For example:
For Each item In extractedTextResults
Console.WriteLine("Extracted result: {0}{1}", item.ToString, vbNewLine)
Next
#5
Re: Read Specific words from txt file
Posted 06 October 2012 - 07:25 AM
Using String.Split Method:
Outputs the ip from the file.
Dim strRead As String = IO.File.ReadAllText("xdos.txt")
Dim ip As String = strRead.Split(New String() {" from "}, StringSplitOptions.None)(1).Split(":")(0)
Console.WriteLine(ip)
Console.ReadKey()
Outputs the ip from the file.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|