DELPHI的代码转换为C#的 100
functionF_Inencrypt(sInput:string):string;stdcall;ConstAllChar:string='abcdefghijklmn...
function F_Inencrypt(sInput: string): string;stdcall;
Const
AllChar:string='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ';
Var
sOutput :string;
iPin:byte;
A: Boolean;
begin
Result := '';
if sInput = '' Then
sOutput := ''
else
begin
A := False;
if Length(sInput) Mod 2 = 1 then
begin
A := True;
sInput := sInput + '_';
end;
for iPin:=1 to Length(sInput) do
begin
sOutput := sOutput+Char(Ord(sInput[iPin]) + 128);
end;
if A then sOutput := sOutput + '_';
end;
Result := PChar(Trim(sOutput));
end;
这个代码在delphi7下运行OK能返回值,我在C#里这样转换
public string F_Encrypt(string sInput)
{
string AllChar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string sOutput;
byte iPin;
Boolean A;
int len = 0;
sOutput = "";
if (sInput == "") sOutput = "";
else
{
A = false;
len = sInput.Length;
if (len % 2 == 1)
{
A = true;
sInput = sInput + "_";
}
for (iPin = 1; iPin <= len; iPin++)
{
sOutput = sOutput + (char)(sInput[iPin] + 128);
}
if (A == true)
{
sOutput = sOutput + "_";
}
}
return sOutput;
}
编译无报错,但是没次都提示超出索引,经排查,似乎是char的问题, 展开
Const
AllChar:string='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ';
Var
sOutput :string;
iPin:byte;
A: Boolean;
begin
Result := '';
if sInput = '' Then
sOutput := ''
else
begin
A := False;
if Length(sInput) Mod 2 = 1 then
begin
A := True;
sInput := sInput + '_';
end;
for iPin:=1 to Length(sInput) do
begin
sOutput := sOutput+Char(Ord(sInput[iPin]) + 128);
end;
if A then sOutput := sOutput + '_';
end;
Result := PChar(Trim(sOutput));
end;
这个代码在delphi7下运行OK能返回值,我在C#里这样转换
public string F_Encrypt(string sInput)
{
string AllChar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string sOutput;
byte iPin;
Boolean A;
int len = 0;
sOutput = "";
if (sInput == "") sOutput = "";
else
{
A = false;
len = sInput.Length;
if (len % 2 == 1)
{
A = true;
sInput = sInput + "_";
}
for (iPin = 1; iPin <= len; iPin++)
{
sOutput = sOutput + (char)(sInput[iPin] + 128);
}
if (A == true)
{
sOutput = sOutput + "_";
}
}
return sOutput;
}
编译无报错,但是没次都提示超出索引,经排查,似乎是char的问题, 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询