nsscanner

NSString *string = @"Product: Acme Potato Peeler; Cost: 0.9873\nProduct: Chef Pierre Pasta Fork; Cost: 0.75 19\nProduct: ChefPierre Colander; Cost: 1.27 2\n";
 

NSCharacterSet *semicolonSet;
NSScanner *theScanner;
 

NSString *PRODUCT = @"Product:";
NSString *COST = @"Cost:";
 

NSString *productName;
float productCost;
NSInteger productSold;
 

semicolonSet = [NSCharacterSetcharacterSetWithCharacte
rsInString:@";"];
theScanner = [NSScanner scannerWithString:string];
 

while ([theScanner isAtEnd] == NO)
{
 
   if([theScanner scanString:PRODUCT intoString:NULL]&&
 
      [theScanner scanUpToCharactersFromSet:semicolonSet
 
          intoString:&productName]&&
 
      [theScanner scanString:@";" intoString:NULL]&&
 
      [theScanner scanString:COST intoString:NULL]&&
 
      [theScanner scanFloat:&productCost]&&
 
      [theScanner scanInteger:&productSold])
 
   {
 
      NSLog(@"Sales of %@: $%1.2f", productName, productCost *productSold);
 
   }
}

帮助我解释代码的逻辑 |// // LMVRKEBitmapParser.m // LMVInsensibilityBlueToothKey // // Created by van on 2025/9/24. // #import "LMVRKEBitmapParser.h" @implementation LMVRKEBitmapParser - (instancetype)initWithBitmapValue:(uint64_t)bitmapValue { self = [super init]; if (self) { _bitmapValue = bitmapValue; } return self; } - (instancetype)initWithHexString:(NSString *)hexString { self = [super init]; if (self) { _bitmapValue = [self parseHexString:hexString]; } return self; } #pragma mark - 解析方法 /// 解析16进制进制字符串 - (uint64_t)parseHexString:(NSString *)hexString { // 移除可能的前缀和空格 NSString *cleanHexString = [hexString stringByReplacingOccurrencesOfString:@"0x" withString:@""]; cleanHexString = [cleanHexString stringByReplacingOccurrencesOfString:@"0X" withString:@""]; cleanHexString = [cleanHexString stringByReplacingOccurrencesOfString:@" " withString:@""]; // 确保长度不超过16个字符 if (cleanHexString.length > 16) { cleanHexString = [cleanHexString substringToIndex:16]; } // 使用NSScanner转换 NSScanner *scanner = [NSScanner scannerWithString:cleanHexString]; uint64_t result = 0; [scanner scanHexLongLong:&result]; return result; } #pragma mark - 查询方法 - (BOOL)isFunctionEnabledAtBit:(NSUInteger)bitPosition { if (bitPosition >= 64) { return NO; } return (self.bitmapValue & ((uint64_t)1 << bitPosition)) != 0; } - (NSInteger)fetchBitForControlType:(LMVInsensibilityBluetooth_ControlType)controlType { switch (controlType) { case LMVInsensibilityBluetooth_WindowControl: return 3; case LMVInsensibilityBluetooth_FrunkControl: return 4; case LMVInsensibilityBluetooth_TrunkControl: return 5; case LMVInsensibilityBluetooth_Honks: return 6; case LMVInsensibilityBluetooth_RightSlidingDoor: return 7; case LMVInsensibilityBluetooth_LeftSlidingDoor: return 8; default: return 0; } } @end
最新发布
09-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值