Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i find string from anoher string like>

string a= "how can i find string from anoher string";(this string or result string should not static)

i want result is like "find string";
Posted
Updated 30-Jul-13 1:35am
v3
Comments
[no name] 30-Jul-13 7:43am    
So get the IndexOf "find string" and SubString.

C#
string a = "this is a string";
string b = "is a";

bool isBinA = a.contains(b);


isBinA will be true in this situation.
 
Share this answer
 
Comments
Joezer BH 30-Jul-13 8:13am    
5ed
chetan2020 30-Jul-13 8:29am    
thanks
Hi chetan,

Firtly - Both the first solutions are of great for your simple purpose.
I want to suggest however, that you learn a bit about Regular Expressions, those will prove extremely useful for search purposes, and are basically a must tool for developers.

See a little example:
C#
string TheText = "Here comes your bulk of text with the pattern to find.";
string WhatToFind_Pattern = "the pattern to find"; // all you have to do is learn some Regex Expressions (see links below the code block ;)
if (System.Text.RegularExpressions.Regex.IsMatch(TheText, WhatToFind_Pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
{
   // Do Stuff
}


Useful links in case you want to get into Regex:
- Learn Regular Expressions (RegEx) with Ease[^]
- Validation with Regular Expressions Made Simple[^]
- Regex Quick Reference[^]


Cheers,
Edo
 
Share this answer
 
Comments
Jean A Brandelero 31-Jul-13 10:12am    
This is a good case for study, i don't think its the best to do this for this specific use. If i had a verified email i may gave you stars. :P
string a = "asdfghijklmnopqrstuvxz";
string b = "hijklm";
bool c = (a.IndexOf(b) > -1);
 
Share this answer
 
Comments
Joezer BH 30-Jul-13 8:13am    
5ed

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