简体   繁体   中英

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. The logic is - if the pattern '%SELECT %FROM% is found in a string called 'x', then I need to return. The '%' stands for 0 or more characters.

The part I am not getting is how to translate the first line of code into C#?

 IF PATINDEX('%SELECT %FROM%',  @x ) > 0 
  BEGIN
     RETURN;
  END

Take a look at regular expresions for C# and the match function..

The pattern would be something like

.*SELECT .*FROM.*

where .* stands for anything other then a new line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM