|
-
Jan 1st, 2008, 12:34 AM
#1
Thread Starter
Member
Remove Content From Text File
I need to know how to remove content from a text file.
basically I am stripping attachments from an Email.
so
IF the text file contains the string
"Content-Type: application/"
Then
Delete the row above that line and everything after that line to the end of the doc
it looks like this
Code:
------=_NextPart_000_xxxxxxxrandomcharactersxxxxxxx
Content-Type: application/pdf;
asdf
asdf
asdfasdf
asdf
asdf
asd
fasd
fasd
fasdf
------=_NextPart_000_xxxxxxxrandomcharactersxxxxxxx
i would want to delete that entire chunk
anyone have any thoughts?
-
Jan 1st, 2008, 12:43 AM
#2
Frenzied Member
Re: Remove Content From Text File
You would scan each line and store each line in an array or list. Then, upon checking each line, if the contents include "Content-Type: application/" then remove the element of the array or list before the current one and all indexes after that element. However, instead of removing all wrong data, which could be a lot, I'd rather suggest you only keeping the data you need. It's a different way to do the same thing, but should be a lot faster. There's your logic. To accomplish this, you can use many classes. How are you getting this email? From a file? In which case you could use a StreamReader, BinaryReader, TextReader, FileStream, or whatever! Take your pick. There's lots of tutorials to be found on google for each.
-
Jan 1st, 2008, 01:00 AM
#3
Thread Starter
Member
Re: Remove Content From Text File
Thanks for the quick reply
Basically I am using raw MAI files to train a bayesian dictionary.
The problem is that the attachments take up HUGE amounts of file space for no reason (11GB at the moment).
Once the dictionary is trained, the files get deleted, so there is no reason to retain the message after processing, but more importantly, i need to remove the attachments from the files.
I see your suggestion about keeping the data I need, but am new to .NET so I am unsure where to start or what terms to Google.
Thanks again...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|