简体   繁体   中英

Objective C string encoding

I seem to be having a problem withs tring encoding.

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)

[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.
You can print any NSObject, including NSStrings, using %@ like this:

NSLog(@"Given: %@ Current: %@ Should BE: %@", url, self.serverUrl, @"http://clanware.com:8000/api");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM