473,480 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

new to streamreader

what i want to do is read in a .ged file and find all the names in the file
and then add them to a listbox. this is what i have and it works but what
can i do better?

thanks,
Rob
public class Gedcom
{
private string gedFile;
private StreamReader fstream;
public Gedcom()
{
//
// TODO: Add constructor logic here
//
}
public string[] GetIndex()
{
//
if (fstream == null)
{
MessageBox.Show("Error opening file stream.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
return null;
}
StreamReader fstreamCopy = fstream;
string textLine;
int index;
bool foundName = false;
ArrayList tmpIndex = new ArrayList();
while (fstreamCopy.BaseStream != null)
{
foundName = false;
try
{
textLine = fstreamCopy.ReadLine().Trim();
index = textLine.IndexOf("INDI");
if (index != -1)
{
while (!foundName)
{
textLine = fstreamCopy.ReadLine().Trim();
index = textLine.IndexOf("NAME");
if (index != -1)
{
tmpIndex.Add(textLine.Substring(index + 4).Trim());
foundName = true;
}
}
}
}
catch
{
fstreamCopy.Close();
}
}
string[] indIndex = new String[tmpIndex.Count];
for (int i = 0; i < tmpIndex.Count; i++)
{
indIndex[i] = tmpIndex[i].ToString();
}
return (indIndex);
//
}
public string OpenGed( string FileName )
{
//
gedFile = FileName;
fstream = File.OpenText(gedFile);
return gedFile;
//
}
}
.....
private void mnuIndex_Click(object sender, System.EventArgs e)
{
frmIndex frmIndex = new frmIndex();
string[] index = ged.GetIndex();
frmIndex.Names = new string[index.Length];
index.CopyTo(frmIndex.Names, 0);
if (frmIndex.ShowDialog(this) == DialogResult.OK)
{
}
}
Nov 15 '05 #1
1 5855

Hi blah,

You want to do better?
Do you refer to improve performance?
I think you can visit the link below to get some information:
http://msdn.microsoft.com/library/de...us/dv_vstechar
t/html/vbtchperfopt.asp

Hope this helps.

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "blah" <bl**@blah.com>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Subject: new to streamreader
| Lines: 92
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <890_a.41474$Bp2.39790@fed1read07>
| Date: Mon, 11 Aug 2003 23:52:42 -0700
| NNTP-Posting-Host: 68.98.17.94
| X-Complaints-To: ab***@cox.net
| X-Trace: fed1read07 1060671172 68.98.17.94 (Tue, 12 Aug 2003 02:52:52 EDT)
| NNTP-Posting-Date: Tue, 12 Aug 2003 02:52:52 EDT
| Organization: Cox Communications
| Path:
cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA05.phx.gbl!TK2MSFTNGP08
phx.gbl!newsfeed00.sul.t-online.de!t-online.de!diablo.theplanet.net!newspee
r1-gui.server.ntli.net!ntli.net!peer01.cox.net!cox.ne t!p01!fed1read07.POSTED
!not-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:175786
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| what i want to do is read in a .ged file and find all the names in the
file
| and then add them to a listbox. this is what i have and it works but what
| can i do better?
|
| thanks,
| Rob
|
|
| public class Gedcom
| {
| private string gedFile;
| private StreamReader fstream;
| public Gedcom()
| {
| //
| // TODO: Add constructor logic here
| //
| }
| public string[] GetIndex()
| {
| //
| if (fstream == null)
| {
| MessageBox.Show("Error opening file stream.", "Error",
MessageBoxButtons.OK,
| MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
| return null;
| }
| StreamReader fstreamCopy = fstream;
| string textLine;
| int index;
| bool foundName = false;
| ArrayList tmpIndex = new ArrayList();
| while (fstreamCopy.BaseStream != null)
| {
| foundName = false;
| try
| {
| textLine = fstreamCopy.ReadLine().Trim();
| index = textLine.IndexOf("INDI");
| if (index != -1)
| {
| while (!foundName)
| {
| textLine = fstreamCopy.ReadLine().Trim();
| index = textLine.IndexOf("NAME");
| if (index != -1)
| {
| tmpIndex.Add(textLine.Substring(index + 4).Trim());
| foundName = true;
| }
| }
| }
| }
| catch
| {
| fstreamCopy.Close();
| }
| }
| string[] indIndex = new String[tmpIndex.Count];
| for (int i = 0; i < tmpIndex.Count; i++)
| {
| indIndex[i] = tmpIndex[i].ToString();
| }
| return (indIndex);
| //
| }
| public string OpenGed( string FileName )
| {
| //
| gedFile = FileName;
| fstream = File.OpenText(gedFile);
| return gedFile;
| //
| }
| }
|
|
| ....
|
|
| private void mnuIndex_Click(object sender, System.EventArgs e)
| {
| frmIndex frmIndex = new frmIndex();
| string[] index = ged.GetIndex();
| frmIndex.Names = new string[index.Length];
| index.CopyTo(frmIndex.Names, 0);
| if (frmIndex.ShowDialog(this) == DialogResult.OK)
| {
| }
| }
|
|
|

Nov 15 '05 #2

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

Similar topics

9
12719
by: oafyuf | last post by:
Hi, I'm having performanbce issues with StreamReader and was wondering what I could do to improve it... The following takes around 3 seconds to process! The content of the response is: ...
5
3027
by: Anders Olsson | last post by:
I need to create a StreamReader which starts from the position of an existing StreamReader. This way, the second StreamReader can read lines "ahead" in an own loop, and then I can go back to the...
11
35684
by: Tiger | last post by:
We can use seek() in the FileStream class,as we know. But I found that seek() is not work correctly in StreamReader. Who can tell me how to use seek() correctly in StreamReader? thanks a lot! I...
2
12978
by: Keith Kingsley | last post by:
I'm using a StreamReader to read in several lines from an ASCII file. I'd like to know the StreamReader's "true" position-- that is, the number of bytes into the file that the StreamReader has...
3
4980
by: Arno | last post by:
Hi, I'm using TcpClient for communication between two PC running a small piece of software. The protocol used has been designed internally and is HTTP similar (command line, headers, body). A...
3
3176
by: Mika M | last post by:
Hello! I'm reading text file line by line using the StreamReader like code below shows. Reading is working fine, but if readed line contains Scandinavian letters like äÄöÖ then those letters are...
3
3093
by: Arpan | last post by:
A file can be read using only the StreamReader object like this: Dim sReader As StreamReader sReader = New StreamReader(Server.MapPath("File1.txt")) While(sReader.Peek -1)...
1
1946
by: garyusenet | last post by:
>From MSDN I'm trying to learn more about streamreader. I'm working my way down the MSDN definition. The first entry is the Public Constructor StreamReader. I'm fairly happy I have a basic grasp on...
1
2680
by: Sladan | last post by:
Im trying to read a xml-file with a StreamReader. For the moment I'm using the following code. streamReader = new StreamReader(stream, System.Text.Encoding.Default); string feedData =...
0
2321
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
6904
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
7034
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,...
0
7076
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6732
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6886
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4768
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1294
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.