Which substring of the string1 matches with the string2.

Posted by Harikrishna on Stack Overflow See other posts from Stack Overflow or by Harikrishna
Published on 2010-04-06T11:25:15Z Indexed on 2010/04/06 11:53 UTC
Read the original article Hit count: 105

Filed under:
|
|
|

There are two strings.

String str1="Order Number Order Time Trade Number";

String str2="Order Tm"; Then I want to know that str2 matches with which substring in the str1.

string regex = Regex.Escape(str2.Replace(@"\ ", @"\s*");
bool isColumnNameMatched = Regex.IsMatch(str1, regex, RegexOptions.IgnoreCase);

I am using regex because "Order Tm" will also matches "Order Time".It gives bool value that matches occurred or not.

Like str2="Order Tm" then it should return like in the str1,Order Time is the substring where matches is occurred.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET