Is there a function / operator in C# that does the same thing as the Like Operator in VB6 / vb.net?
If not, would it be worth building a quick class lib in VB that encapsulates it so we C Sharpers can use it?
Printable View
Is there a function / operator in C# that does the same thing as the Like Operator in VB6 / vb.net?
If not, would it be worth building a quick class lib in VB that encapsulates it so we C Sharpers can use it?
What the hell I've done it anyway!
Compile that in a Class Library in VB. Start a new C# project, add a reference to your new VB dll and then off you go!Code:Public Class OldVB
Shared Function StrLike(ByVal str As String, ByVal mask As String) As Boolean
Return str Like mask
End Function
End Class
The release version of the above VB code comes in at a truly huge 5kb!
Code://C#
OldVB.StrLike("Smith", "Sm[iy]th*")); //returns true :D
OldVB.StrLike("Jones", "Sm[iy]th*")); //returns false :D
Viva la.Net.
You could argue that this belongs in the VB.net forum, but it is only for the benefit of C# and other non-vb coders really :)
Isn't that function exist under "Microsoft.VisualBasic" namespace ?
Can't find it, probably because it was an operator to begin with.
VB Code:
Public Class OldVB Shared Function StrLike(ByVal str As String, ByVal mask As String) As Boolean Return str Like mask End Function End ClassPHP Code:public static bool StrLike(string str, string mask)
{
return Microsoft.VisualBasic.CompilerServices.StringType.StrLike(str, mask, 0);
}
Try this if it really works (well , it's working well for me) . At least , it's fully managed code ;)
PHP Code:bool Like(string str1 , string str2)
{
//0 = exactly like
//1 = like
//-1 = not like
if (string.Compare(str1,str2)==0)
return true;
else if (string.Compare(str1,str2)==1)
return true ;
else return false;
}