John Woo
John Woo

Reputation: 263683

Delphi to VBNet Code Conversion (How to?)

I have this Delphi code:

function EnDeCrypt(const Value : String) : String;
var
CharIndex : integer;
begin
    Result := Value;
    for CharIndex := 1 to Length(Value) do
    Result[CharIndex] := chr(not(ord(Value[CharIndex])));
end;

how can it be translated to .Net?

Upvotes: 1

Views: 982

Answers (1)

David Heffernan
David Heffernan

Reputation: 612794

If the function that RRUZ provided (now deleted) is really what you want (and I'm still a little sceptical of the encoding issues) then you can write it like this:

Private Function EnDeCrypt(ByVal Value As String) As String

    Dim transformed = Encoding.Unicode.GetBytes(Value).Select( _
        Function(item) Not item)
    Return Encoding.Unicode.GetString(transformed.ToArray())

End Function

Upvotes: 3

Related Questions