Hi Guys
I'm having problems converting this code below from vb.net to c# can someone please help ??
Public Function CryptData(ByVal Text As String) As String
Dim strTempChar As String
Dim i As Integer
For i = 1 To Len(Text)
If Asc(Mid$(Text, i, 1)) < 128 Then
strTempChar = CType(Asc(Mid$(Text, i, 1)) + 128, String)
ElseIf Asc(Mid$(Text, i, 1)) > 128 Then
strTempChar = CType(Asc(Mid$(Text, i, 1)) - 128, String)
End If
Mid$(Text, i, 1) = Chr(CType(strTempChar, Integer))
Next i
Return Text
End Function
This is the code after I convert it to C#
public string CryptData(string Text)
{
string strTempChar = null;
int i = 0;
for (i = 1; i <= Len(Text); i++)
{
if (Asc(Mid(Text, i, 1)) < 128)
{
strTempChar = Convert.ToString(Asc(Mid(Text, i, 1)) + 128);
}
else if (Asc(Mid(Text, i, 1)) > 128)
{
strTempChar = Convert.ToString(Asc(Mid(Text, i, 1)) - 128);
}
Mid(Text, i, 1) == Chr(Convert.ToInt32(strTempChar));
}
}
The application is giving loads of errors like
Error 1 The name 'Len' does not exist in the current context
Error 2 The name 'Asc' does not exist in the current context
Error 3 The name 'Mid' does not exist in the current context
Can someone please help me ???
Regards
VX
Loading
theLizardPosted Jul 1, 2010, 9:25 PM
Asc = Char.ConvertToUtf32(Text, 1);
Mid = Text.SubString(i, 1)
so the statement
if (Asc(Mid(Text, i, 1)) < 128)
becomes
If(Char.ConvertToUtf32(Text, 1) < 128)
{
.....
}
strTempChar = Convert.ToString(Asc(Mid(Text, i, 1)) + 128);
becomes
int d = Char.ConvertToUtf32(Text, i);
strTempChar = Char.ConvertFromUtf32(d);
can you work the rest out for yourself.
VikramPosted Jul 1, 2010, 9:58 AM
Please refer following.
http://www.developerfusion.com/tools/convert/vb-to-csharp/
This is one utility which convert VB.NET code to C#.Net and vice versa.
Regards,
Vikram