I have a notepad with in fix format sentence 开发者_StackOverflow社区like
name...
Image...
Text...
I need to read all Text option with given criteria from notepad.
First i need calculate all words which are starting with #.
Second i need to calculate repeated word excluding like a,an,the,is,am,are,do,did.
How can i calculate this?
tempAccounts = GlobusFileHelper.ReadFiletoStringList(Path);
foreach (string AcctData in tempAccounts)
{
string[] tempArray = AcctData.Split(':');
foreach (string accounts in tempAccounts)
{
DecaptchaAccounts.Add(accounts);
}
}
For each of the words in the file, add them to a C# List. As you add them, if List.Contains(item to add), then flag this as a duplicate, (unless it is one of the words you want to exclude)
This may be a long shot, to get text from an open instance of notepad you will need to get down with the Windows API :
First you need to get the running instances of notepad :
Process[] processes = Process.GetProcessesByName("notepad");
Then iterate through them
foreach (Process p in processes)
{
IntPtr pFoundWindow = p.MainWindowHandle;
....
P/Invoke GetNextWindow to find the top window which contains the text..
HWND GetNextWindow(HWND hWnd, UINT wCmd );
Then send a WM_GETTEXT message to that window which should retrieve the text..
Then you can parse the text and count the words.
So, you want to read a text file, look for particular lines in that text file, and do stuff with the text you read from it, right?
There are plenty of options here, but it's not clear you've looked at any of them. You can read this file using one of the various Stream/TextReader classes, but I'm going to guess (for now) that you want a very simple API for doing this.
Take a look at the System.IO.File class and the members it exposes...
http://msdn.microsoft.com/en-us/library/system.io.file_methods.aspx
File exposes a ReadAllLines method which is a very simple API for reading all the lines from a text file into an array.
http://msdn.microsoft.com/en-us/library/system.io.file.readalllines.aspx
This might not be the best API if you've got massive files, but it's a really easy way of consuming the lines in a text file.
Once you have the array everthing else you describe is simple to do - process each item in the array doing your counting and processing as you see fit.
精彩评论