[英]Objective C string encoding
I seem to be having a problem withs tring encoding. 我似乎在使用tring编码时遇到问题。
I have the following code: 我有以下代码:
// Sets the server url and whether or not the server is logged in
- (Server *) init:(NSString *) url {
// Setup the singleton!
_instance = self;
// Store our own copy of the string
self.serverUrl = [[NSString alloc] initWithString:url];
self.is_logged = NO;
NSLog(@"Given: %s Current: %s Should BE: %s", url, self.serverUrl, @"http://clanware.com:8000/api");
return self;
}
` `
The object is instantiated as follows: 该对象的实例如下:
self.server = [[Server alloc] init:@"http://clanware.com:8000/api"];
NSLog(@"URL in Server: %s", self.server.serverUrl);
I get the following output in gdb (I'm running this in xcode) 我在gdb中得到以下输出(我正在xcode中运行它)
[Session started at 2010-12-02 11:55:35 -0400.]
2010-12-02 11:55:40.388 ProjectPrototype[1765:207] Given: `üô» Current: `üô» Should BE: `üô»
2010-12-02 11:55:40.390 ProjectPrototype[1765:207] URL in Server: `üô»
Any help would be appreciated, I'm lost and am not sure what to do! 任何帮助将不胜感激,我迷路了,不知道该怎么办!
Thanks alot =) 非常感谢=)
you shouldn't use %s
on NSLog for NSStrings. 您不应该在NSLog的
%s
上使用NSStrings。
You can print any NSObject, including NSStrings, using %@
like this: 您可以使用
%@
打印任何NSObject,包括NSString,如下所示:
NSLog(@"Given: %@ Current: %@ Should BE: %@", url, self.serverUrl, @"http://clanware.com:8000/api");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.