Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do string comparison with wildcard pattern in C#

Tags:

c#

asp.net

Did C# provide any method to compare the string with a wildcard pattern like. Or I can say I want to find a "Like Operator" to do string comparison. Suppose I have a string .I also have a paragraph , I want to find the string on this parapgraph,But how.In SQL we can do it just using the LIKE operator.

Any Suggestion and reply is grateful.

like image 524
shamim Avatar asked Aug 01 '10 04:08

shamim


People also ask

How do I compare strings in C?

The strcmp() function, is used to compare the strings (str1,str2). The strings str1 and str2 will be compared using this function. If the function returns a value 0, it signifies that the strings are equal otherwise, strings are not equal.

Which wildcards are used for pattern matching?

Use the asterisk ( * ) to match any sequence or string of characters. The ( * ) indicates any characters, including no characters.

Can you use comparison operators on strings?

The comparison operators also work on strings. To see if two strings are equal you simply write a boolean expression using the equality operator.

Which symbol is used for wildcard in a search string?

You can use the asterisk (*) anywhere in a character string.


1 Answers

Wildcards are a complicated beast (a form of regular expressions), but it sounds like you want the Contains method. You can just do paragraph.Contains(sentence).

like image 157
Gabe Avatar answered Sep 30 '22 14:09

Gabe