Searching a string for multiple words using C#

This is what I need to do. I wrote it in Psudocode

Examples of string coming from client computer:
string1: "Disk "ST380013AS (Ch2)" failed
String2: "Rebuilding successfully completed for disk "ST380013AS (Ch2)"

Function for the strings: Server side

      private void ReceiveData(Byte [] byteBuffer, int size)
      {
         string sData = Encoding.ASCII.GetString(byteBuffer,0, size);

            if (sData) contains words "Disk" and "failed" (either lower or uppercase)
              then
                      //pop up the screen for the user
                      open up messagebox or form that contains "Disk Failure" This form or messagebox must stay on
                      top of all applications (focus) until the user closes it.
                 ***Need to do try catch here

            else if (sData) contains the words "Disk", "Rebuilding" and "Successfully" (either lower or uppercase)
              then
                       //Post the message into the errorlog
                System.Diagnostics.EventLog.WriteEntry(this.ToString(),"OCSEventListener" + sData);
               ***Need to do try catch here


Questions need answered
Can I use 1 function to do both strings or do I need 2 functions?
Does anyone have an example on performing the search of the string for the mulitple words?
LVL 2
NewMom2BrandonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HendrikTYRCommented:
       private void ReceiveData(Byte [] byteBuffer, int size) {
            string sData = Encoding.ASCII.GetString(byteBuffer,0, size);

            if((sData.ToLower().IndexOf("disk") > 0) &&
                (sData.ToLower().IndexOf("failed") > 0)) {
                // do your message box stuff here
            }
            else if((sData.ToLower().IndexOf("disk") > 0) &&
                (sData.ToLower().IndexOf("rebuilding") > 0) &&
                (sData.ToLower().IndexOf("successfully") > 0)) {
                // do your errorlog stuff here
            }
        }
0
HendrikTYRCommented:
Sorry, make that:

private void ReceiveData(Byte [] byteBuffer, int size) {
            string sData = Encoding.ASCII.GetString(byteBuffer,0, size);

            if((sData.ToLower().IndexOf("disk") > -1) &&
                (sData.ToLower().IndexOf("failed") > -1)) {
                // do your message box stuff here
            }
            else if((sData.ToLower().IndexOf("disk") > -1) &&
                (sData.ToLower().IndexOf("rebuilding") > -1) &&
                (sData.ToLower().IndexOf("successfully") > -1)) {
                // do your errorlog stuff here
            }
        }

.... the MSDN documentation on this is actually incorrect....
in your second string IndexOf("Rebuilding") returns zero, which is the index of that word, but according to the MSDN docs on IndexOf(string value):
Return Value
Value                                        Meaning
A positive index position.             value was found.
0                                              value is Empty.          (this is incorrect)
-1                                             value was not found.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NewMom2BrandonAuthor Commented:
I am looking to make sure the word is in the string so would it still be -1 or would it be 1
I want the messagebox to pop up when the two value disk and failed are in the string. same for the other the values but instead of the message box it just writes into the error log.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

NewMom2BrandonAuthor Commented:
ok scratch my last comment...thank you for you help
0
HendrikTYRCommented:
Yip, use the code from my second posting:  If IndexOf(...) returns a value higher than -1 it means the word was found.

Do you need help with the message box and errorlog stuff as well?
0
NewMom2BrandonAuthor Commented:
I have the information for the errorlog stuff. I belive it is just

System.Diagnostics.EventLog.WriteEntry(this.ToString(),sData);

I am a little stuck on how to make the messagebox stay up on the screen. I have another application that is running and this is to pop up from outside the application so it needs to stay on top of everything until the user clicks it. Do you have any suggestions on that
0
HendrikTYRCommented:
Try this:

MessageBox.Show("Your warning message", "WARNING!!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
0
NewMom2BrandonAuthor Commented:
I saw this under the foxpro. Do I need to include the 4096 into the messagebox example you provided

You can make sure your messagebox stays on top of all other applications by using

messagebox("Error!",4096,"System Message")

the 4096 makes the messagebox system modal.  You can add this to the standard messagebox parameters for example

messagebox("Error!",4096+36,"System Message")

will display the 'Error!' message with a Yes and No dialogue box.
0
HendrikTYRCommented:
not needed...

MessageBoxOptions.ServiceNotification will keep it on top, even when nobody is logged on.
0
NewMom2BrandonAuthor Commented:
ahh thank you so much for your help!! You have saved me hours of digging!!
0
NewMom2BrandonAuthor Commented:
One more question is there a way to make the messagebox be full screen or at least large enough to be an annoyance?
0
HendrikTYRCommented:
Tough one...
If you put in a very long message...yes
Quick and dirty solution:  
string errMsg = "Whatever your message is".PadLeft(300, ' ').PadRight(300, ' ');
...hehe
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.