论坛: 编程破解 标题: C语言与Objective-C字符串转换 复制本贴地址    
作者: NetDemon [netdemon]    ADMIN   登录
因为objectc是构建在c上的,所以有必要理解如何在c语言字符串和objc字符串进行转换

例子如下

// NSString object to C
NSString *str = @"String object to a C string";
const char *ptr = [str cStringUsingEncoding:NSUTF8StringEncoding];
printf("%s\n", ptr);

// Another approach with the same result
const char *ptr2 = [str UTF8String];
printf("%s\n", ptr2);

// C string to NSString object
ptr = "C string to string object";
str = [NSString stringWithCString:ptr encoding:NSUTF8StringEncoding];
NSLog(@"%@", str);

地主 发表时间: 11-10-29 04:54

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号