过滤“输入”来自richTextbox Content [英] Filter "Enter" from richTextbox Content
问题描述
我正在编写一个代码,用于比较richtextbox内容和字符(字符代码),然后显示一个MessageBox。
这是我的代码:
Hi,
I am writing a code that compare richtextbox content with character(character code) , and then show a MessageBox .
this is my code :
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");
}
此代码运行时没有问题,
例如:我在richtextbox中写了一个q,(q的代码是113)。当这个程序转到if语句比较所有字符然后找到q和MessageBox.Show(Test);跑 。
它是对的,但我希望这个程序比较输入对我来说。如何将richtextbox中的所有字符与Enter进行比较(这意味着如果在richtextbox内容中使用Enter,则返回一条消息)?!
提前致谢
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
推荐答案
试试这些:
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;
}
}
}
这篇关于过滤“输入”来自richTextbox Content的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!