Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reading the file from specific line to specific line

Posted on 2013-12-30
5
Medium Priority
?
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 680 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 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 660 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:Hiran Desai
Hiran Desai earned 660 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

618 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