Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > In file parsing, taking the first few characters of a text file after a readfile or streamreader file read...

Reply
Thread Tools

In file parsing, taking the first few characters of a text file after a readfile or streamreader file read...

 
 
.Net Sports
Guest
Posts: n/a
 
      01-16-2006
In VB.net, I'm trying to do a couple of things in a couple of different
blocks of code. I need to take the first 25 characters of a text file,
then append at the end some ellipses and a MORE link to a webpage where
viewers can read the rest of the article:
This is the first few characters of text from my file.......<a
href="article-to-read.aspx"> MORE </a>
...I also need to do some in file parsing where I start at one known
keyword (START for an example) , grab all the text until , let's say
the next </td>, put it all into a variable, and then be able to use
that variable to display the results of all the text from START to
</td> . IndexOf seems like the builtin function I may need to use, but
having difficulty finding methods and arguments to do in file searching
for this.

thanks
netsports

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      01-16-2006
Sorry,
that was C# (I'm VB.NET - challenged) but you get the idea.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




".Net Sports" wrote:

> In VB.net, I'm trying to do a couple of things in a couple of different
> blocks of code. I need to take the first 25 characters of a text file,
> then append at the end some ellipses and a MORE link to a webpage where
> viewers can read the rest of the article:
> This is the first few characters of text from my file.......<a
> href="article-to-read.aspx"> MORE </a>
> ...I also need to do some in file parsing where I start at one known
> keyword (START for an example) , grab all the text until , let's say
> the next </td>, put it all into a variable, and then be able to use
> that variable to display the results of all the text from START to
> </td> . IndexOf seems like the builtin function I may need to use, but
> having difficulty finding methods and arguments to do in file searching
> for this.
>
> thanks
> netsports
>
>

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      01-16-2006
You want to use the Substring method, combined with IndexOf and related for
stuff like this.

string newStr =MyText.Substring(0, 25)
or
string newStr=MyText.Substring(0, MyText.LastIndexOf("<BR>");


Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




".Net Sports" wrote:

> In VB.net, I'm trying to do a couple of things in a couple of different
> blocks of code. I need to take the first 25 characters of a text file,
> then append at the end some ellipses and a MORE link to a webpage where
> viewers can read the rest of the article:
> This is the first few characters of text from my file.......<a
> href="article-to-read.aspx"> MORE </a>
> ...I also need to do some in file parsing where I start at one known
> keyword (START for an example) , grab all the text until , let's say
> the next </td>, put it all into a variable, and then be able to use
> that variable to display the results of all the text from START to
> </td> . IndexOf seems like the builtin function I may need to use, but
> having difficulty finding methods and arguments to do in file searching
> for this.
>
> thanks
> netsports
>
>

 
Reply With Quote
 
.Net Sports
Guest
Posts: n/a
 
      01-16-2006
Thanks....

.....can anyone provide a vb.net equivalent?

 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      01-16-2006
The VB.Net equivalent of:

string newStr =MyText.Substring(0, 25)
or
string newStr=MyText.Substring(0, MyText.LastIndexOf("<BR>");

is:

Dim newStr As String =MyText.Substring(0, 25)
or
Dim newStr As String=MyText.Substring(0, MyText.LastIndexOf("<BR>")

......

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

".Net Sports" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Thanks....
>
> ....can anyone provide a vb.net equivalent?
>



 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      01-16-2006

http://www.eggheadcafe.com/articles/...converter.aspx

You might want to bookmark that.
Don't forget to remove illegal characters like in "<BR>"

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




".Net Sports" wrote:

> Thanks....
>
> .....can anyone provide a vb.net equivalent?
>
>

 
Reply With Quote
 
.Net Sports
Guest
Posts: n/a
 
      01-16-2006
Thanks for the input (and converter, Peter)..
..I'm getting a substring not a member of 'System.IO.StreamReader'
error when trying this. And also, I'm not using any type of input
control (for the MyText. prefix)
thanks
netsports

Kevin Spencer wrote:
> The VB.Net equivalent of:
>
> string newStr =MyText.Substring(0, 25)
> or
> string newStr=MyText.Substring(0, MyText.LastIndexOf("<BR>");
>
> is:
>
> Dim newStr As String =MyText.Substring(0, 25)
> or
> Dim newStr As String=MyText.Substring(0, MyText.LastIndexOf("<BR>")
>
> .....
>
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> You can lead a fish to a bicycle,
> but it takes a very long time,
> and the bicycle has to *want* to change.
>
> ".Net Sports" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...
> > Thanks....
> >
> > ....can anyone provide a vb.net equivalent?
> >


 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      01-16-2006
Ok, well you'll need to post some sample code so the incredible cadre of
helpful experts here can show how to fix it. Substring is a method on the
string class, has nothing to do with StreamReader.

Example:

Dim xyz as String
xyz="12345678901234567890"
Dim abc as String = xyz.Substring(0,9)

--Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




".Net Sports" wrote:

> Thanks for the input (and converter, Peter)..
> ..I'm getting a substring not a member of 'System.IO.StreamReader'
> error when trying this. And also, I'm not using any type of input
> control (for the MyText. prefix)
> thanks
> netsports
>
> Kevin Spencer wrote:
> > The VB.Net equivalent of:
> >
> > string newStr =MyText.Substring(0, 25)
> > or
> > string newStr=MyText.Substring(0, MyText.LastIndexOf("<BR>");
> >
> > is:
> >
> > Dim newStr As String =MyText.Substring(0, 25)
> > or
> > Dim newStr As String=MyText.Substring(0, MyText.LastIndexOf("<BR>")
> >
> > .....
> >
> > Kevin Spencer
> > Microsoft MVP
> > .Net Developer
> > You can lead a fish to a bicycle,
> > but it takes a very long time,
> > and the bicycle has to *want* to change.
> >
> > ".Net Sports" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) ups.com...
> > > Thanks....
> > >
> > > ....can anyone provide a vb.net equivalent?
> > >

>
>

 
Reply With Quote
 
.Net Sports
Guest
Posts: n/a
 
      01-16-2006
<%Dim mystring As StreamReader =
File.OpenText("c:\inetpub\wwwroot\articles\thefile .txt")
If File.Exists("c:\inetpub\wwwroot\articles\thefile.t xt") = True Then
Do While mystring.Peek() >= 0
dim firsttext as string =Substring(mystring(0,25))
response.write(firsttext.ReadLine())
Loop
mystring.Close()
End If

 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      01-17-2006
OK. Lets refactor that a bit and clean it up:


Dim mystring as as string = String.Empty
Dim path as String = "c:\inetpub\wwwroot\articles\thefile.txt"
Try
If File.Exists(path) Then
Dim sr As StreamReader = New StreamReader(path)
'This allows you to do one Read operation.
mystring =sr.ReadToEnd()
sr.Close()
Catch e As Exception
' handle the exception
Response.Write ("The process failed: {0}", e.ToString())
End Try
End If
' on mystring, which now holds the entire file contents, you can apply the
Substring method as described earlier.

Hope that helps.


--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




".Net Sports" wrote:

> <%Dim mystring As StreamReader =
> File.OpenText("c:\inetpub\wwwroot\articles\thefile .txt")
> If File.Exists("c:\inetpub\wwwroot\articles\thefile.t xt") = True Then
> Do While mystring.Peek() >= 0
> dim firsttext as string =Substring(mystring(0,25))
> response.write(firsttext.ReadLine())
> Loop
> mystring.Close()
> End If
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Streamreader is holding a text file in its grip after it is closed damezumari ASP .Net 2 04-27-2006 02:28 PM
To delete few lines and add few lines at the end of a text file using c program Murali C++ 2 03-09-2006 04:45 PM
Grabbing the first characters of a textfile using StreamReader or ReadFile in vb.net .Net Sports ASP .Net 0 01-11-2006 03:20 PM
StreamReader doesn't pick up special characters Max ASP .Net 4 11-18-2004 12:52 AM
How to check for EOF (End of file) when using StreamReader to parse text file Sacha Korell ASP .Net 2 09-06-2003 02:59 PM



Advertisments