Solved

Parsing a RichText Box like a file?

Posted on 2003-10-24
4
207 Views
Last Modified: 2010-04-16
I am trying to parse email. I have created a richtext box that allows me to drag and drop an email file over it and the email appears in the RichText Box. I want to be able to step through that RichText Box line by line and parse it. Can I use similar commands for stepping through a file to step through the RichText Box? Here is the code that I used to drag and drop the email file into the RichText Box.

private void Form1_Load(object sender, System.EventArgs e)
{          
this.richTextBox1.DragEnter += new System.Windows.Forms.DragEventHandler(this.richTextBox1_DragEnter);  
this.richTextBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.richTextBox1_DragEnter);  
this.richTextBox1.AllowDrop = true;
}

private void richTextBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)  
{  
if (((DragEventArgs)e).Data.GetDataPresent(DataFormats.Text))  
     ((DragEventArgs)e).Effect = DragDropEffects.Copy;
 
else  
     ((DragEventArgs)e).Effect = DragDropEffects.None;  
}
 
private void richTextBox1_DragDrop(object sender, DragEventArgs e)  
{  
richTextBox1.LoadFile((String)e.Data.GetData("Text"), System.Windows.Forms.RichTextBoxStreamType.RichText);  
}

Thanks!
0
Comment
Question by:kingjamez
4 Comments
 
LVL 2

Accepted Solution

by:
smitty22 earned 125 total points
ID: 9615618
You can use RichTextBox's Lines property to get a string array of the lines currently in the text box.
0
 
LVL 6

Assisted Solution

by:zrh
zrh earned 125 total points
ID: 9618785
You can do something like:

StringReader sr = new StringReader(richTextBox1.Text);

StringReader is a descendant of System.IO.TextReader, so that might be what you want.

However, in your richTextBox1_DragDrop event instead of using the LoadFile method, you could open the file yourself using a StreamReader, and parse while writing it to the RichTextBox.
That might give you better performance for larger files, so that you don't have to *essentially* read them twice.

Hope that helps,
ZRH
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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