我正在尝试获取类似的字符串\x8
并将字节附加到data
. 不幸的是,每当我使用@"\\x8
OBJ-C 时,它都无法识别它是十六进制代码。哪种编码或如何编码以便我可以使用动态转义序列?
样本:
- (void)selectStandardPrinterMode:(int)font isEmphasized:(BOOL)emphasized isDoubleSize:(BOOL)size isUnderline:(BOOL)line
{
NSMutableString *printerMode;
unsigned int hex;
switch (font)
{
case 0:
hex = 0;
break;
case 1:
hex = 1;
break;
default:
hex = 0;
NSLog(@"[font]: unknown option");
break;
}
if (emphasized)
{
hex += 8;
}
if (size)
{
hex += 30;
}
if (line)
{
hex += 80;
}
if (hex > 100)
{
hex -= 100;
printerMode = [NSString stringWithFormat:@"%@%u", @"\xb", hex];
}
else
{
printerMode = [NSString stringWithFormat:@"%@%u", @"\\x", hex];
}
// not working
[_data appendBytes:ESC "!" length:2];
[_data appendBytes:[printerMode cStringUsingEncoding:NSASCIIStringEncoding] length:1];
// working example
[_data appendBytes:ESC "!" "\x8" length:3];
}