Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

Please tell me how to search a string including space also...

e.g. if i search What is

then it should count the space also and after fetching the result in a gridview it should highlight the whole search string..
Posted
Updated 4-Oct-12 21:42pm
v2
Comments
♥…ЯҠ…♥ 5-Oct-12 3:39am    
Hi nandy,
Can u elaborate on your question? where u want to search? give us some examples so that we can help you out.

We can get solution using like operator in sql server

select * from emp where empname='%test t%'
 
Share this answer
 
Let say your search String is
C#
string searcStr = "Hello world";


now you want to search this string in a paragraph;
C#
string paragrph = @"Your first application, HelloApp, will simply display the greeting 'Hello world!'.";


C#
if (paragrph.Contains(searcStr))
           Response.Write("The search string found at" + paragrph.IndexOf(searcStr)+" character position");
 
Share this answer
 
v3
Comments
[no name] 5-Oct-12 3:47am    
i have 2 tables which contains 300 questions each..i have to search from there..and please tell how to highlight the search text inside gridview
I am not sure whether you have searched for this over internet or not. In C# you can use Contains method or IndexOf method of the String class and search for a substring..
 
Share this answer
 
C#
string st="this is my test string";
int result=IndexOf("this"," ");
 
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