Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Microsoft.VisualBasic.CompilerServices.LikeOperator.LikeString中带有特殊字符的模式不起作用_C#_Vb.net_Vba_Design Patterns - Fatal编程技术网

C# Microsoft.VisualBasic.CompilerServices.LikeOperator.LikeString中带有特殊字符的模式不起作用

C# Microsoft.VisualBasic.CompilerServices.LikeOperator.LikeString中带有特殊字符的模式不起作用,c#,vb.net,vba,design-patterns,C#,Vb.net,Vba,Design Patterns,我尝试使用LikeOperator.LikeString功能进行模式匹配,如下所示: // Usage: bool matchValue = LikeOperator.LikeString(string, pattern, CompareMethod); bool match = LikeOperator.LikeString("*test*/fe_quet", "(*)test(*)/*", Microsoft.VisualBasic.CompareMethod.Text);

我尝试使用LikeOperator.LikeString功能进行模式匹配,如下所示:

    // Usage: bool matchValue = LikeOperator.LikeString(string, pattern, CompareMethod);
    bool match = LikeOperator.LikeString("*test*/fe_quet", "(*)test(*)/*", Microsoft.VisualBasic.CompareMethod.Text);
根据文档,上面的内容应该返回true,但它只返回false。我试着用括号来逃避*的影响,但它似乎并没有以那种方式起作用。有人能帮我定义带有特殊字符的模式字符串吗

感谢您提供了:

要匹配左括号中的特殊字符[、问号、数字符号和星号*,请将它们括在括号中

因此,您需要将星号包装在[]中,而不是:

bool match = LikeOperator.LikeString("*test*/fe_quet", "[*]test[*]/[*]", Microsoft.VisualBasic.CompareMethod.Text);

您最好使用正则表达式而不是VB名称空间。

@WiktorStribiżew我不明白,这里没有提到这种情况:您能为我键入完整的模式字符串吗?谢谢lot@WiktorStribiżew不幸的是,预先结束波浪线将不会逃逸模式字符串中的星号。它没有逃逸工作:实际上,我需要对模式字符串中的星号进行转义,因为它们在模式字符串中有不同的含义零个或多个字符匹配。如果您需要正则表达式解决方案,我可以帮助您使用正则表达式。但是,在这种情况下,使用字符集[…]后,这些通配符就可以了@WiktorStribiżew我以前在使用正则表达式时遇到了一些问题,因此我决定使用这个功能!啊,就这样!非常感谢,所以没有正确阅读它是错误的。再次感谢一位朋友:我对正则表达式语言不熟悉,所以我想保持它的简单,更好地使用它使用LikeOperator。你认为用它代替Regex有什么大问题吗?它没有问题,但是微软建议不要直接使用这个函数,即使是在VB中。类似VB的操作符调用这个函数。