//NSString转换char
NSString * str1= @"Test";
const char * c1 =[str1 UTF8String];
//char转换NSString
const char * c2 ="test";
NSString *str2 = [NSString stringWithUTF8String:c2];
NSString* str1=@"01 00 20 00 01 10 30 31 32 33 34 35 36 37 38 FF FF FF FF FF FF FF";
const char *str2=[str1 UTF8String];
unsigned char source[22];
int i;
int v;
for (i=0;i<22;i++) {
sscanf(str2+i*3,"%2X",&v);
source[i]=(unsigned char)v;
printf("%d=%X\n",i,source[i]);
}
- 传入NSString对象值,char *作为方法参数
有链接教程:http://www.cnblogs.com/chenleiustc/archive/2011/04/09/2010647.html
NSString *str = @"NSString转换为char并转换作为方法参数传递"
const char *c1 =[str UTF8String];
char *cc =(char*)&c1;//通过强制类型转换,将地址赋给变量,再作修改即可以改变const常量值。
Test *pTest = new Test();
pTest->init(cc);
void init(char *str); // 方法含char参数