How to remove hexadecimal characters from NSString

前端 未结 3 1684
时光取名叫无心
时光取名叫无心 2021-01-22 14:49

I am facing one issue related some hexa value in string, i need to remove hexadecimal characters from NSString.

The problem is when i print object it prints as \"BLANK

3条回答
  •  猫巷女王i
    2021-01-22 15:39

    As your dataset clearly has garbage values, You can use this method to check if your string is valid or not. Define your validation criteria and simply don't entertain the values which are garbage. But as suggested before by gnasher, you should rather look for the bug which is causing insertion of garbage data in your database. Once you have done that, check if the input string matches your defined criteria. If it does, do what you want. If it doesn't, simply move on.

    -(BOOL) isValidString: (NSString*) input
    {
             NSMutableCharacterSet *validSpecialChars = [NSMutableCharacterSet characterSetWithCharactersInString:@"_~.,"];//Add your desired characters here
             [validSpecialChars formUnionWithCharacterSet:[NSCharacterSet alphanumericCharacterSet]];
             return [[input stringByTrimmingCharactersInSet:validSpecialChars] isEqualToString:@""];
    }
    

    If your string will contain only your defined characters, it will return true. If it contains any other characters (garbage or invalid) it will return false.

提交回复
热议问题