gpt4 book ai didi

iphone - 从服务器加载 "weird characters"的标签

转载 作者:行者123 更新时间:2023-12-01 18:22:23 26 4
gpt4 key购买 nike

我在 View 中有一个标签,它加载纯文本文件并显示内容,但它显示不位于 .txt 文件中的奇怪字符以及真实内容。

文本文件中有一行:“更新提交”

这就是它在实际设备本身上的样子。


如您所见,“更新已提交”标签前面有 2 个奇怪的字符。

我正在使用这段代码:

content = [NSString stringWithContentsOfURL:[NSURL
URLWithString:@"http://samguichelaar.com/soadstatus.txt"] encoding: 1 error: NULL];
Label1.text = content;

提前致谢!

最佳答案

您正在使用 ASCII 编码。切换到 UTF8 编码:

URLWithString:@"http://samguichelaar.com/soadstatus.txt"] encoding:NSUTF8StringEncoding error: NULL]

此外,您应该使用 Apple 为任何字符串编码提供的常量,以防 Apple 决定他们想要更改与任何常量关联的值:

http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html

搜索 NSStringEncoding

关于iphone - 从服务器加载 "weird characters"的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16482516/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com