Click here to Skip to main content
15,122,559 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to find various words in a single string so for this i am using string.contains("") but it only find single word and i want to search multiple words:
Ex : A,B,C,D
so i want check that string contain these four value or not
Thanks
Posted
Comments
   
Call it harder... :-)

The question is very illogical. You failed to use Contains and asking how to use it, as if Contain would be the only possibility. I'm sure you have brain, but I not using it? For now, you get my 1 for being so lazy to fail to do minimal search by yourself and use simple logic.

Sorry,
--SA

string.contains, Returns a value indicating whether the specified String object occurs within this string.
so you can not check multiple values using it.

You can, Collect all text (that you want to search) in string array and loop through it using .Contains
   
Comments
sharad_sharma82 21-Jan-12 3:50am
   
I have datalist control where i call iframe for showing pdf file:
1. <%# Eval("fileupload4") != "" && Eval("fileupload4").ToString().Contains(".pdf")? "<iframe id='iframes' width='900px' height='300px' runat="server" src='iframe.aspx?filename=Eval('fileupload4').ToString()'></iframe>" :
here i am checking that file extension is pdf or not
2. <asp:Image Width="100" ID="Image1" Style="color: White; border-width: 0px;" Height="100px"
ImageUrl='<%# Bind("fileupload4", "~/QuizAttachment/{0}") %>' runat="server" />
in this i also want to check that the file extension is ".jpeg,gif,.bmp" so that i ll use same column for image control for showing image
Thanks
String.Contains will only search for a single string: you will have to do multiple searches if you continue to use it.
You could use a Regex:
C#
public static Regex regex = new Regex("hello|hola|salut", RegexOptions.IgnoreCase 
    | RegexOptions.CultureInvariant
    | RegexOptions.IgnorePatternWhitespace
    | RegexOptions.Compiled
    );

// Capture all Matches in the InputText
MatchCollection ms = regex.Matches(InputText);
   
Comments
sharad_sharma82 21-Jan-12 3:50am
   
I have datalist control where i call iframe for showing pdf file:
1. <%# Eval("fileupload4") != "" && Eval("fileupload4").ToString().Contains(".pdf")? "<iframe id='iframes' width='900px' height='300px' runat="server" src='iframe.aspx?filename=Eval('fileupload4').ToString()'></iframe>" :
here i am checking that file extension is pdf or not
2. <asp:Image Width="100" ID="Image1" Style="color: White; border-width: 0px;" Height="100px"
ImageUrl='<%# Bind("fileupload4", "~/QuizAttachment/{0}") %>' runat="server" />
in this i also want to check that the file extension is ".jpeg,gif,.bmp" so that i ll use same column for image control for showing image
Thanks
OriginalGriff 21-Jan-12 4:01am
   
And your problem is? Or are you expecting me to write all the code for you?

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