如何在给定的字符串中查找逗号 [英] how to find the comma in given string

查看:137
本文介绍了如何在给定的字符串中查找逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个文本框,输入的文本总是像textbox.text ="text1,text2"
但是当用户输入这样的文本时textbox.text ="text1"

那么如何检查逗号并添加文本.
如何编写用于检查逗号的ode并在c#中添加空字符串
我的输出像
textbox.text ="text1,''''";

hi all,

i have one text box enter text always like textbox.text="text1,text2"
but when user enter the text like this textbox.text="text1"

so how to check comma and add the text.
how to write a ode for check comma and adding empty string in c#
my output like
textbox.text="text1,''''";

推荐答案

每个字符串都有一个contains方法
Every string has a contains method[^]. Just check for a comma using contains within the string.


请检查以下一项:-

http://stackoverflow.com/Questions/2586602/best-way-to-way-to-check-for-string-in-逗号分隔列表-with-net [ ^ ]
Check this one :-

http://stackoverflow.com/questions/2586602/best-way-to-check-for-string-in-comma-delimited-list-with-net[^]


您可以在"TextBox1_Change"事件中进行检查,例如:


if(Text1.Text.IndexOf(,")> = 0)
{
//TODO:如果在文本框字符串中找到逗号,则您想做什么?????
}
其他
{
//TODO:如果在文本框字符串中找不到逗号,则您想做什么?????
}
You can check it on "TextBox1_Change" event like :


if(Text1.Text.IndexOf(",") >= 0)
{
// TODO : If Comma found in textbox string, what u want to do ?????
}
else
{
// TODO : If Comma not found in textbox string, what u want to do ?????
}


这篇关于如何在给定的字符串中查找逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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