[英]C# equivalent of PATINDEX function in SQL Server 2008
I have the following SQL Server code which I would like to do in C# code. 我有以下SQL Server代码,我想用C#代码。 The logic is - if the pattern '%SELECT %FROM% is found in a string called 'x', then I need to return.
逻辑是 - 如果在名为'x'的字符串中找到模式'%SELECT%FROM%,那么我需要返回。 The '%' stands for 0 or more characters.
'%'代表0或更多字符。
The part I am not getting is how to translate the first line of code into C#? 我没有得到的部分是如何将第一行代码转换为C#?
IF PATINDEX('%SELECT %FROM%', @x ) > 0
BEGIN
RETURN;
END
Take a look at regular expresions for C# and the match function.. 看一下C#和匹配函数的常规表达式。
The pattern would be something like 模式会是这样的
.*SELECT .*FROM.*
where .* stands for anything other then a new line. where。*表示除了新行之外的任何其他内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.