Skip to content

Parse text file in c#

Sanfoor Sanfoor

Asked May 2, 2015, 4:26 AM EDT1 answer
Share
LinkedInX
i have the following text file which is marked in bold , i need to extract the ip addresses(in red) from it in c#
any help please?
 ----------------------------------------------------------------------------------
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1460
;; QUESTION SECTION:
;www.youtube.com. IN A

;; ANSWER SECTION:
www.youtube.com. 74304 IN CNAME youtube-ui.l.google.com.
youtube-ui.l.google.com. 118 IN A 213.139.46.102
youtube-ui.l.google.com. 118 IN A 213.139.46.88
youtube-ui.l.google.com. 118 IN A 213.139.46.89
youtube-ui.l.google.com. 118 IN A 213.139.46.110
youtube-ui.l.google.com. 118 IN A 213.139.46.96
youtube-ui.l.google.com. 118 IN A 213.139.46.123
youtube-ui.l.google.com. 118 IN A 213.139.46.109
youtube-ui.l.google.com. 118 IN A 213.139.46.116
youtube-ui.l.google.com. 118 IN A 213.139.46.117
youtube-ui.l.google.com. 118 IN A 213.139.46.82
youtube-ui.l.google.com. 118 IN A 213.139.46.95
youtube-ui.l.google.com. 118 IN A 213.139.46.103

;; Query time: 1151 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Fri May 01 23:56:52 EEST 2015
;; MSG SIZE rcvd: 270

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • -1
    You can read text file by using below code, e.g.,


    C#
    List<string> output=new List<string>();
    using (StreamReader sr = new StreamReader("E:\\op.html"))         {             string line;             while ((line = sr.ReadLine()) != null)             {
                     if(line.Contains("youtube-ui.l.google.com. 118 IN A "))
    
                                    {
                                            output.Add(line.Replace("youtube-ui.l.google.com. 118 IN A ","");
                                    }
    
                 }
            }
    //Now you'll get result in variable output
    
    
    
    
    Please accept answer if this works for you. Thanks
    -1