Solved

Reading the file from specific line to specific line

Posted on 2013-12-30
5
265 Views
Last Modified: 2014-01-02
I want to get a substring between <body> to </body>

Dim Files As String() = System.IO.Directory.GetFiles("c:\temp\temp1")
            Dim readpages As New ReadingPages()
            For Each sFile As String In Files
                If readpages.IsaspxFile(sFile) Then
                    Dim fileCont As String = System.IO.File.ReadAllText(sFile)
                    'it found something
                    If fileCont.Contains("<body>") = True Then
                     'I want to read the contents from <body> to </body>
                    End If
                End If
               
            Next

Open in new window


Thanks
0
Comment
Question by:KavyaVS
5 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 170 total points
ID: 39746854
Try:
...

        If fileCont.Contains("<body>") = True Then

            Dim startOffset = fileCont.IndexOf("<body>") + 5
            Dim endOffset = fileCont.IndexOf("</body>")

            Dim body As String = fileCont.Substring(startOffset, endOffset - startOffset)
            Debug.WriteLine(body)

        End If
...

Open in new window

0
 
LVL 35

Assisted Solution

by:Miguel Oz
Miguel Oz earned 165 total points
ID: 39747036
See my answer at:
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_28327525.html#a39747030

It seems to be a duplicate question here. Any way my answer compared to Carl's and your original code has the following improvements:
1) Get Files method only retrieves aspx files: (System.IO.Directory.GetFiles("c:\temp\temp1", "*.aspx")
)
2) The body tag is only searched once using index. (No need for fileCont.Contains)
0
 
LVL 4

Assisted Solution

by:ItWorked
ItWorked earned 165 total points
ID: 39748005
why don't you try with
String.Split(String[],StringOptions)

Open in new window

method ?

may be like this...
String [] sepraters=new String [] {"<body>","</body>"};

String HTML=System.IO.ReadAllText("file");
var values=HTML.split(sepraters,StringSplitOptions.RemoveEmptyEntries);
// values[0] = will be first part before <body>
// values[1] = middle part between <body>,</body>
// values[2] = rest of string till end

Open in new window

0
 

Author Closing Comment

by:KavyaVS
ID: 39751647
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now