Solved

Reading the file from specific line to specific line

Posted on 2013-12-30
5
264 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

20 Experts available now in Live!

Get 1:1 Help Now