|
Easiest way is probably to use a regex:
string inp = File.ReadAllText(@"D:\Temp\MyText.txt");
string match = "FindMe";
int count = Regex.Matches(inp, match, RegexOptions.IgnoreCase).Count; This has the advantage that the user can use regex wildcards for more complex jobs if they want.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
Hey I've just posted my code, hopefully that helps!
I had a look at the code you posted and the problem is I'm looking within an array as opposed of comparing against a single string.
Many thanks,
Katie.
|
|
|
|
|
Try using the IndexOf(string, StringComparison)[^] method:
if (line1.IndexOf(cust1[AddressLength1].ToString(), StringComparison.OrdinalIgnoreCase) != -1)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
First, the IndexOf() method has an overload that takes a StringComparison enumeration value, so you could just add the second parameter StringComparison.OrdinalIgnoreCase (or .CurrentCultureIgnoreCase or .InvariantCultureIgnoreCase , as appropriate).
However, this code is a bit strange...
Are you really writing the message to the same file you are scanning?
If not, it appears you are doing potentially a lot of extra work (e.g., reading the inbox(?) file multiple times).
How about something like this:
if (!String.IsNullOrEmpty(CustodianEAddressText))
{
List<string> list1 = new List<string>();
using (StreamReader reader = new StreamReader(FileLocation))
{
string line1;
while ((line1 = reader.ReadLine()) != null)
{
list1.Add(line1);
}
}
for (AddressLength1 = 0; AddressLength1 < Length; AddressLength1++)
{
string cust1AddrLen1 = cust1[AddressLength1].ToString();
count1 = list1.Count(l => l.IndexOf(cust1AddrLen1, StringComparison.OrdinalIgnoreCase) != -1);
string[] LineArray1 = (from line in list1
where line.IndexOf(cust1AddrLen1, StringComparison.OrdinalIgnoreCase) != -1
select line).ToArray();
count1 = LineArray1.Length;
string count1a = count1.ToString();
using (StreamWriter filed = new StreamWriter(FileLocation, true))
{
filed.WriteLine();
filed.WriteLine("The email address {0} was found {1} times within the recipient's inbox", cust1AddrLen1, count1a);
}
}
}
else
{
MessageBox.Show("Please Enter an Email Address");
}
|
|
|
|
|
hi
I am a beginner, i want to build an application in C# to send an sms to multiple numbers without using an sms gateway, i want to use my internet connection to send sms and access 2007 to store sms and other details. if someone can help then please help.
regards,
Arif Aqeel
|
|
|
|
|
Arif_Aqeel wrote: I am a beginner, i want to build an application in C# to send an sms to multiple numbers without using an sms gateway, i want to use my internet connection to send sms and access 2007 to store sms and other details.
This goal is clearly too high for a beginner. Start from scratch and do easy stuff to get to harder stuff. An address management with access as database would be a good start.
|
|
|
|
|
|
|
IDK but can it somehow be possible that you have forgot to actually ask a question?
ProTip: Use the Edit-Button under your post to add an actual question.
|
|
|
|
|
The OP has really cheered up my day. Finally post that literally doesn't have a question, or even an attempt at one. Not even an "itz urgentz plz help" plea. Almost zen-like in depth-through-simplicity.
|
|
|
|
|
|
Seriously, click edit and add a question, we can't help if we don't know what the problem is.
|
|
|
|
|
|
|
Take a look at the AForge.Net framework, it has a component for this kind of algorithms:
AForge.NET Framework
This is the namespace you might be interested in:
•AForge.Genetic - evolution programming library;
|
|
|
|
|
I'm trying to open openoffice/Libreoffice impress(simpress.exe) in my C# windows form.
But it opens in its own window and there is no data on form.
I want to integrate it in my form.
This is my code:
ProcessStartInfo proc = new ProcessStartInfo();
proc.FileName = @"C:\Program Files\LibreOffice 4.0\program\simpress.exe";
proc.UseShellExecute = true;
var process = Process.Start(proc);
Thread.Sleep(2000);
SetParent(process.MainWindowHandle, this.Handle);
It open Libreoffice impress but not in my form.
How can I integrate it with my form?
Thanks!
|
|
|
|
|
toms from newdelhi wrote: It open Libreoffice impress but not in my form. That is what the Process.Start method is designed for. I do not know if it is possible to open this within your form. You need to study the openoffice SDK to see what features it supports.
Use the best guess
|
|
|
|
|
toms from newdelhi wrote: It open Libreoffice impress but not in my form.
How can I integrate it with my form?
Because LibreOffice is still loading and building it's form when you call SetParent . Try to WaitForInputIdle[^] before changing the parent.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I used it but its not working.
I used process.WaitForInputIdle() but getting the same result.
Thanks!
|
|
|
|
|
I have no idea how you can integrate it with your forms. You cannot use Process.Start to integrate any form with you custom form. Try to find any Library control like OCX control so that they can be integrated with your forms. But try this one [^]. I hope this will help you.
First and the Foremost: FIGHT TO WIN
|
|
|
|
|
Actually, you can. It takes a fair bit of interop work, but it is possible. Basically, you reparent the application into yours.
|
|
|
|
|
I thought that COM automation is used for these jobs. OpenOffice would/should have registered a COM automation object for external applications to call the automation server (dll).
www.oooforum.org/forum/viewtopic.phtml?t=9815
"It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan
That's what machines are for.
Got a problem?
Sleep on it.
|
|
|
|
|
You could do it this way, but you can also reparent other application windows.
|
|
|
|
|
OK, this is new to me.
I'll go and take a look.
"It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan
That's what machines are for.
Got a problem?
Sleep on it.
|
|
|
|
|
Actually I'm trying to integrate OpenOffice/LibreOffice in my C# windows form program.
But I'm getting bootstrap error.
So I thought to do it in this way.
Is it not possible to integrate it in C# program.
Do anyone having any idea of doing it?
Please suggest.
|
|
|
|