473,387 Members | 3,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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

Jan 16 '06 #1
11 2784
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

Jan 16 '06 #2
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

Jan 16 '06 #3
Thanks....

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

Jan 16 '06 #4
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" <ba********@cox.net> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Thanks....

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

Jan 16 '06 #5

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?

Jan 16 '06 #6
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" <ba********@cox.net> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Thanks....

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


Jan 16 '06 #7
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" <ba********@cox.net> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Thanks....

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


Jan 16 '06 #8
<%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

Jan 16 '06 #9
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

Jan 17 '06 #10
And kindly note that as I explained, I obviously remain quite VB.NET
challenged:
the last two lines:
End Try
End If
should be reversed:

End If
End Try

Have you ever thought about C#? :-)
--
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

Jan 17 '06 #11
Thanks a bunch for the help, looks like this is getting me on my way.
Yep, I do need to develop C# skills, but I do need more an overall
grasp of .net technologies at the same time.
netsports

Jan 17 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Neil Patel | last post by:
I have a log file that puts the most recent record at the bottom of the file. Each line is delimited by a \r\n Does anyone know how to seek to the end of the file and start reading backwards?
3
by: JSM | last post by:
Hi, I am just trying to port an existing simple encryption routine to C#. this routine simply adds/substracts 10 ascii characters to each character in a text file (except quotes). The routine...
31
by: microsoft.news.com | last post by:
I need to read a text file but I need to start on line 2 of the file, How can I start reading the text file starting with the second line and not the first line in the file?
4
by: Kueishiong Tu | last post by:
I have a text file with wide characters. I use the following C++ code to read them in. However the wide characters are not read in properly. What is wrong? String* path = "C:\\Documents and...
4
by: ESPN Lover | last post by:
Below is two snippets of code from MSDN showing how to read a file. Is one way preferred over the other and why? Thanks. using System; using System.IO; class Test { public static void...
12
by: Adam J. Schaff | last post by:
I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like: ...
4
by: moondaddy | last post by:
I need to edit the text in many files so I'm writing a small routine to do this. First I have a method that loops through all the files in a directory and passes the full file path to another...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
0
by: rajana | last post by:
Dear All, We have Ansi file with german characters (Ä / Ø) , We are using Streamreader to read the contents of the file. But Readline() not able to read the German characters. We tried all...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.