FTP传文件中文乱码问题,求大神解决
delphi吧
全部回复
仅看楼主
level 5
随云home 楼主
服务器端接收的含中文的文件名,中文都是乱码,我用AnsiToUtf8,UTF8Decode,Utf8ToAnsi,UTF8Decode,UTF8Encode,AnsiString
这些函数都转换了也没有效果,不用函数也不行,其中UTF8Decode和Utf8ToAnsi不能传,会报错,我用的XE6,请问有大神遇到同样的问题了吗,怎么解决的?
2015年08月13日 03点08分 1
level 5
随云home 楼主
有人没,我自己顶一下
2015年08月14日 06点08分 5
level 5
随云home 楼主
我发现我的文件名乱码是通过两次转换成的,假设文件名问你‘hello你好’,用下面的函数转换
转换成这样,再用得到的字符串转换成字节显示就是和文件名乱码一样的,
其中log是memo显示; 然后我再把乱码还原,怎么还原不到中间的‘hello浣犲ソ.txt’;
现在问题只需要把这个’helloä½ å¥½.txt‘还原成这个‘hello浣犲ソ.txt’就好办了,有没有大神帮我看看
2015年08月15日 07点08分 8
‘hello浣犲ソ.txt’转换成’helloä½ å¥½.txt‘ 是通过下面代码转的,我还原过来就不行了 ///string转为Tbytes (转换成和文件名一样的乱码) Byte := BytesOf(S1); Edit2.Text := BytesToStr(Byte, 'str');
2015年08月15日 07点08分
回复
����home
:BytesToStr 在新版本中找不到了。 设 str := 你收到的乱码 ABytes :=TEncoding.ANSI.GetBytes(str); ANewStr := TEncodign.UTF8.GetStr(ABytes);
2015年08月17日 02点08分
str := 'helloä½ å¥½.txt'; ABytes :=TEncoding.ANSI.GetBytes(str); ANewStr := TEncoding.UTF8.GetString(ABytes); 我这样写有什么问题吗,报错
2015年08月17日 09点08分
@wang_80920 我把str赋值为字母或数字不报错,但换成乱码和中文是转不过来的。
2015年08月17日 09点08分
level 5
随云home 楼主
{****16进制单字符值*****}
function HexVal(c: char): Byte;
begin
if (c<'A') then result := ord(c) - ord('0')
else result := ord(c) - ord('A') + 10;
end;
{****16进制双字符值*****}
function Hex2Val(s: string): Byte;
begin
result := HexVal(s.Chars[0])*16 + HexVal(s.Chars[1]);
end;
{**********字符串转换成字节*******}
function StrToBytes(S, AFormat: string): TBytes;
var
i:Integer;
ss:TStrings;
begin
if(AFormat='Str') then begin
SetLength(result,s.Length);
for i:=0 to s.Length-1 do result[i]:=ord(s.Chars[i]);
end else begin
ss:=TStringList.Create;
ss.CommaText:=s.Trim.ToUpper.Replace(' ',',');
SetLength(result,ss.Count);
if(AFormat='HexStr') then for i:=0 to ss.Count-1 do result[i]:=Hex2Val(ss[i]);
if(AFormat='DecStr') then for i:=0 to ss.Count-1 do result[i]:=ss[i].ToInteger;
ss.Free;
end
end;
{**********字节转换成字符串*******}
function BytesToStr(b: TBytes; AFormat: string): string;
var
I: Byte;
begin
result := '';
if (AFormat = 'str') then for i in b do result := result + chr(I) else
if (AFormat = 'HexStr') then for I in b do result := result + I.ToHexString(2) + '' else
if (AFormat = 'DecStr') then for i in b do result := result + I.ToString() + '';
result := result.Trim;
end;
2015年08月18日 01点08分 12
level 5
随云home 楼主
我把原码放在这里,各位大神有空的话可以帮我看看[玫瑰]
[无效] http://pan.baidu.com/s/1c0jmZSk
2015年08月18日 01点08分 13
level 5
随云home 楼主
谢谢楼上两位大哥[花心]
2015年08月20日 09点08分 19
level 5
随云home 楼主
然后我把楼上大哥的代码写成函数,直接将乱码转换成中文了,真是太感谢 太感谢[哈哈]
2015年08月20日 12点08分 20
1