当我扫描条形码时,如果它是Equal=2 ,我会得到一些值,那么我需要用==显示,如果它是Equal=3,那么我需要用=显示,如果该值为 4,则无效。
但是扫描条码是整数值——当使用NSASCII
它解码时,它只显示直到值127
,之后它显示无效结果。例如:如果我的条形码值 =9699
结果值 =jem
那么我添加的结果值 =jem=
实际字符串值 = %å
asc值 id 只显示37
这是我的代码:
- (void) readerView:(ZBarReaderView *)view didReadSymbols:(ZBarSymbolSet *)syms fromImage:(UIImage *)img
{
// do something useful with results -- cool thing is that you get access to the image too
for (ZBarSymbol *symbol in syms) {
[resultsBox setText:symbol.data];
if ([resultsBox.text length] == 2) {
addedresult.text = [resultsBox.text stringByAppendingString:@"=="];
} else if ([resultsBox.text length] == 3) {
addedresult.text = [resultsBox.text stringByAppendingString:@"="];
} if ([resultsBox.text length] >= 4) {
addedresult.text = @"Invalid";
}
[Base64 initialize];
NSString *myString = [[NSString alloc]initWithString:addedresult.text];
NSData * data = [Base64 decode:myString];
NSString * actualString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"%@",actualString);
labeltext.text= actualString;
int asc = [actualString characterAtIndex:0];
label.text = [NSString stringWithFormat:@"%d", asc];
[actualString release];
break;
}
}