Click here to Skip to main content
15,888,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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,''";
Posted

Every string has a contains method[^]. Just check for a comma using contains within the string.
 
Share this answer
 
v2
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 ?????
}
 
Share this answer
 
C#
if (textbox1.Text.Contains(',')
{
    // Comma exists
}
else
{
    // Comma is not existed
}
 
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