怎样把这一段字符串转换成123456 NSString *str=@"313233343536";//这是123456的ascii码怎样把这一段字符串转换成123456呢NSString *string = [NSString stringWithFormat:@"%c", asciiCode]; // 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 原来是CC的zzxap啊, 123456的ascii码不应该是 "49 50 51 52 53 54"嘛? - (NSString *)TextFromAsciiCodesString:(NSString *)string{ NSArray *components = [string componentsSeparatedByString:@" "]; NSUInteger len = [components count]; char new_str[len+1]; int i; for (i = 0; i < len; ++i) new_str[i] = [[components objectAtIndex:i] intValue]; new_str[i] = '\0'; return [NSString stringWithCString:new_str encoding:NSASCIIStringEncoding];}转换后输出就是123456 NSString *str=@"495051525354"; const char* cstr = [str UTF8String]; printf("%s\n", cstr); char result[strlen(cstr) / 2 + 1]; int resultIdx = 0; for(int i=0; i<strlen(cstr); i+=2){ char* tmp = malloc(3); tmp[0] = cstr[i]; tmp[1] = cstr[i+1]; tmp[2] = '\0'; int a = atoi(tmp); //printf("%d\n", a); result[resultIdx++] = a; free(tmp); } result[strlen(cstr) / 2] = '\0'; printf("%s\n", result);你的ASCII码是错的 ios开发超级群,高手和高手之间的交流,来者注明来自CSDN:43146334 NSString *str=@"495051525354"; const char* cstr = [str UTF8String]; printf("%s\n", cstr); char result[strlen(cstr) / 2 + 1]; int resultIdx = 0; for(int i=0; i<strlen(cstr); i+=2){ char* tmp = malloc(3); tmp[0] = cstr[i]; tmp[1] = cstr[i+1]; tmp[2] = '\0'; int a = atoi(tmp); //printf("%d\n", a); result[resultIdx++] = a; free(tmp); } result[strlen(cstr) / 2] = '\0'; printf("%s\n", result);ios开发超级群,高手和高手之间的交流,来者注明来自CSDN:43146334 楼主的ASCII码没错,是16进制的 我错了。返回的数据是NSDATA 直接转为uft8 的NSString就行了 IOS Apple APNS 消息推送 C# 能不能获取Itune数据 NSXMLparser parse函数问题 iOS开发的样式 Iphone 有用来开发的模拟器吗? 关于UICollectionView的问题~ 在xcode的storyboard中怎么使多控件等距排列 Xcode 在MainStoryBoard里循环显示xib的文件,怎么再往mainStoryBoard里加入控件? jsonModel 取值问题 如何实现在同一wifi下将用电脑下载手机沙盒文件 使用 cocos2d-x 和 lua 开发游戏(不使用box2d), 空闲时间想学iphone手机开发,求前辈指教~
{
NSArray *components = [string componentsSeparatedByString:@" "];
NSUInteger len = [components count];
char new_str[len+1];
int i;
for (i = 0; i < len; ++i)
new_str[i] = [[components objectAtIndex:i] intValue];
new_str[i] = '\0';
return [NSString stringWithCString:new_str
encoding:NSASCIIStringEncoding];
}
转换后输出就是123456
NSString *str=@"495051525354";
const char* cstr = [str UTF8String];
printf("%s\n", cstr);
char result[strlen(cstr) / 2 + 1];
int resultIdx = 0;
for(int i=0; i<strlen(cstr); i+=2){
char* tmp = malloc(3);
tmp[0] = cstr[i];
tmp[1] = cstr[i+1];
tmp[2] = '\0';
int a = atoi(tmp);
//printf("%d\n", a);
result[resultIdx++] = a;
free(tmp);
}
result[strlen(cstr) / 2] = '\0';
printf("%s\n", result);你的ASCII码是错的
NSString *str=@"495051525354";
const char* cstr = [str UTF8String];
printf("%s\n", cstr);
char result[strlen(cstr) / 2 + 1];
int resultIdx = 0;
for(int i=0; i<strlen(cstr); i+=2){
char* tmp = malloc(3);
tmp[0] = cstr[i];
tmp[1] = cstr[i+1];
tmp[2] = '\0';
int a = atoi(tmp);
//printf("%d\n", a);
result[resultIdx++] = a;
free(tmp);
}
result[strlen(cstr) / 2] = '\0';
printf("%s\n", result);ios开发超级群,高手和高手之间的交流,来者注明来自CSDN:43146334