使用 stringByRepectingCharacters InRange
来替换仅第一层和:
NSString* s = @"Select * from Store_Master where AND VDivison = Casual Dining AND VBrand_Name = Pinkberry AND VCountry_Name = Egypt AND VCity = Cairo AND VBuilding_mall_name = Dandy Mega Mall GROUP BY VStore_Name";
NSRange replaceRange = [s rangeOfString:@"AND"];
if (replaceRange.location != NSNotFound){
NSString* result = [s stringByReplacingCharactersInRange:replaceRange withString:@""];
}
这将导致:
Select * from Store_Master where VDivison = Casual Dining AND VBrand_Name = Pinkberry AND VCountry_Name = Egypt AND VCity = Cairo AND VBuilding_mall_name = Dandy Mega Mall GROUP BY VStore_Name
编辑:
如果您想要在不敏感的情况下删除 和
的出现( 无关紧要的小写大写), 请在创建 NSRange 时使用 < code> NSStringCompareops code>, 例如 :
NSRange replaceRange = [s rangeOfString:@"and" options:NSCaseInsensitiveSearch];
代码的其余部分是相同的。