用于stringByReplacingCharactersInRange
仅替换第一个 'AND':
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
编辑:
如果您想以AND
不区分大小写的方式删除出现的 (无论是大写还是小写),请NSStringCompareOptions
在创建 NSRange 时使用 ,如下所示:
NSRange replaceRange = [s rangeOfString:@"and" options:NSCaseInsensitiveSearch];
其余代码相同。