检查文本框是否有分号 [英] Checking if the textbox has a semicolon

查看:149
本文介绍了检查文本框是否有分号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!如何检查在文本框中输入的数据是否有分号。我知道我应该使用正则表达式条件,但我不知道如何在条件下正确实现分号。有帮助吗?提前谢谢。

Hi! How can I check if the data entered in textbox has a semicolon. I am aware that I should use the regex condition, but I don''t get how to properly implement the semicolon on the condition. Any help? Thank you in advance.

推荐答案

当然可以使用上面描述的IndexOf方法,但是有一个名为Contains的方法专门为此设计:



You can use the IndexOf method as described above of course, but there is a method called Contains that is especially designed for this:

if (myTxtBox.Text.Contains(";"))
{
    // box contains a ; so do something here
}




你也可以用字符串.Contains()方法检查另一个字符串中字符串的存在。



示例 - :

Hi,
You can also use string.Contains() method to check existance of a string in another string.

Example-:
bool hasSemiColon=textBox1.Text.Contains(";");


使用字符串方法IndexOf从文本中查找分号。



IndexOf:

此方法查找char参数的第一个索引。如果找不到char,则返回-1。



例如

use string method IndexOf to find the semicolon from text.

IndexOf:
This method finds the first index of the char argument. It returns -1 if the char was not found.

e.g.
string x = txtValue.Text;
bool hasSemicolon = x.IndexOf(';') == -1 ? false : true;


这篇关于检查文本框是否有分号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆