How to convert HEX to NSString in Objective-C?

后端 未结 5 1586
终归单人心
终归单人心 2020-11-27 22:06

I have a NSString with hex string like \"68656C6C6F\" which means \"hello\".

Now I want to convert the hex string into another NSString object which shows \"hello\"

5条回答
  •  鱼传尺愫
    2020-11-27 22:40

    I think the people advising initWithFormat is the best answer as it's objective-C rather than a mix of ObjC, C.. (although the sample code is a bit terse).. I did the following

    unsigned int resInit = 0x1013;
    if (0 != resInit)
    {
        NSString *s = [[NSString alloc] initWithFormat:@"Error code 0x%lX", resInit];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Initialised failed"
            message:s
            delegate:nil
            cancelButtonTitle:@"OK"
            otherButtonTitles:nil];
        [alert show];
        [alert release];
        [s release];
    }
    

提交回复
热议问题