Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Hi friends,
i have a string in c#.

exp="I,II,III,IV,V";

i want to check for example II is exists in the exp then it return true otherwise return false.

Thanks....

Randeep Chauhan
Posted
Comments
Peter_in_2780 10-Jun-11 1:35am    
Ever looked at the methods of the String class? There are several you could use.

If you want false for "I,III,IV,V", use
exp.Split(",").Contains("II")


if you want true for "I,III,IV,V", then use
exp.Contains("II")
 
Share this answer
 
Comments
Randeep Chauhan 10-Jun-11 1:50am    
Thank friends it solve my problem,befor this i use exp.contain('I')
Randeep Chauhan
Prerak Patel 10-Jun-11 1:58am    
You are welcome.
Hope This helps you :



string str6= "I,II,III,IV";
string[] str4 = str6.Split(',');

string ss=Array.Find<string>(str4, el => el.StartsWith("II"));
 
Share this answer
 
Comments
fjdiewornncalwe 22-Jun-11 8:53am    
Overkill in a huge way. Just use the built in .Contains method.

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