请问这段c#代码用vb怎么写?
private static string sqlEncode(string sqlString)
{
string Result= " ";
for (int i=0; i <sqlString.Length; i++)
Result+= (sqlString[i]== '\ ' ' ? "\ '\ ' " : sqlString[i]+ " ");
return Result;
}
------解决方案--------------------dim i as integer
for i=0 to sqlString.length
if sqlString(i)= '\ ' '
result+= "\ '\ ' "
else
result+=sqlString(i)
end if
next for
------解决方案--------------------Function sqlEncode(ByVal sqlString As String) As String
Dim Result As String = " "
For i As Integer = 0 To sqlString.Length
Result += IIf(sqlString.Substring(i, 1) = " ' ' ", " ' ' ' ' ", sqlString.Substring(i, 1))
Next
Return Result
End Function
------解决方案--------------------Private Shared Function sqlEncode(ByVal sqlString As String) As String
Dim Result As String = " "
Dim i As Integer = 0
While i < sqlString.Length
Result += (Microsoft.VisualBasic.IIf(sqlString(i) = " ' "C, " ' ' ",sqlString(i) + " "))
System.Math.Min(System.Threading.Interlocked.Increment(i),i-1)
End While
Return Result
End Function
------解决方案--------------------Private Shared Function sqlEncode(ByVal sqlString As String) As String
Dim Result As String = " "
Dim i As Integer = 0
While i < sqlString.Length
Result += (Microsoft.VisualBasic.IIf(sqlString(i) = " ' "C, " ' ' ",sqlString(i) + " "))
System.Math.Min(System.Threading.Interlocked.Increment(i),i-1)
End While
Return Result
End Function
--------------------------------------------
顶楼上。
------解决方案-------------------- '你的代碼是要把一個單引號換成兩個單引號,只需要替換就好了。
Function sqlEncode(ByVal sqlString As String) As String
return sqlString .Replace( " ' ", " ' ' ")
End Function