Click here to Skip to main content
15,897,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am writing a code that compare richtextbox content with character(character code) , and then show a MessageBox .

this is my code :

C#
char[] st = new char[richTextBox1.Text.Length];
       st =  richTextBox1.Text.ToCharArray(0, richTextBox1.Text.Length);
       int a;



       for (int i = 0; i <= richTextBox1.Text.Length-1; i++)
       {
           a = Convert.ToInt32(st[i]);
           if (a == 113)
           {
               MessageBox.Show("Test");
           }


this code is running without problem for characters ,

as example : I have wrote a "q" in richtextbox , (code of "q" is 113) . when this program go to if statement compare all character and then find "q" and MessageBox.Show("Test"); run .

it is right but I want to this program compare "Enter" for me . How can I compare all characters in richtextbox with "Enter" ( It mean if "Enter" used in richtextbox content , return me a message ) ?!


Thanks in advance
Posted

1 solution

Try these:
C#
private char chr_return = '\n';

private void rtfHasReturn()
{
     if (richTextBox1.Text.Contains(chr_return)) MessageBox.Show("test");
}

// want fancier looking ?
private void rtfFindFirstReturn()
{
   foreach(char c in richTextBox1.Text)
   {
       if (c == chr_return)
       {
           MessageBox.Show("test");
           break;
       }
   }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900