Click here to Skip to main content
15,895,794 members
Please Sign up or sign in to vote.
1.11/5 (5 votes)
See more:
Hi Pls convert this code into vb.net, i am try in on-line convert,i am getting error in delegate,

C#
protected static string SqlEscape(string str)
   {
       return Regex.Replace(str, @"[\x00'""\b\n\r\t\cZ\\%_]",
           delegate(Match match)
           {
               string v = match.Value;
               switch (v)
               {
                   case "\x00":            // ASCII NUL (0x00) character
                       return "\\0";
                   case "\b":              // BACKSPACE character
                       return "\\b";
                   case "\n":              // NEWLINE (linefeed) character
                       return "\\n";
                   case "\r":              // CARRIAGE RETURN character
                       return "\\r";
                   case "\t":              // TAB
                       return "\\t";
                   case "\u001A":          // Ctrl-Z
                       return "\\Z";
                   default:
                       return "\\" + v;
               }
           });
   }


Or change the code without delegate,,,,

Regards
Aravind
Posted
Updated 10-May-15 23:41pm
v2

1 solution

Use this: http://converter.telerik.com/[^]
VB
Function Compare(match As Match) As String
    Dim v As String = match.Value
    Select Case v
        Case vbNullChar
            ' ASCII NUL (0x00) character
            Return "\0"
        Case vbBack
            ' BACKSPACE character
            Return "\b"
        Case vbLf
            ' NEWLINE (linefeed) character
            Return "\n"
        Case vbCr
            ' CARRIAGE RETURN character
            Return "\r"
        Case vbTab
            ' TAB
            Return "\t"
        Case ChrW(26)
            ' Ctrl-Z
            Return "\Z"
        Case Else
            Return Convert.ToString("\") & v
    End Select
End Function

Protected Shared Function SqlEscape(str As String) As String
    Return Regex.Replace(str, "[\x00'""\b\n\r\t\cZ\\%_]", AddressOf Compare)
End Function
 
Share this answer
 
v2
Comments
Aravindba 11-May-15 7:47am    
Thank u for ur reply,i already try with telerik converter and also other online converter,i am getting error near delegate ,in c# word is delegate but in vb.net after convert "sub(match as Match),here i get error ,pls add in sample vb.net application and check,it gives error.
Kornfeld Eliyahu Peter 11-May-15 8:02am    
Which means that no-one anymore interested in converting code to VB :-)...
Answer updated...
(You have to learn how to find answers to questions using Google! Also to be able to understand compiler errors!)
Aravindba 11-May-15 8:17am    
Thank u for ur update ,still got error ,here i attach screenshot link,http://prntscr.com/73z2g9 i am add ur code in aspx page.And i dont want convert code as it is in c#,is any other way achieve this way in vb.net.
Kornfeld Eliyahu Peter 11-May-15 8:33am    
As I told you - you have to learn to read error messages!!!
The actual problem is that 'SqlEscape' is a shared (static) method where 'Compare' is not - fix it...
Aravindba 11-May-15 9:59am    
Thank u for ur comments,now work fine,thanx a lot 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900