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
I'm not sure exactly what you are looking for, but if you want to remove all the control characters then
string = [[string componentsSeparatedByCharactersInSet:[NSCharacterSet controlCharacterSet]] componentsJoinedByString:@""]
If you need to be faster and are sure the control characters are only at the beginning and ending of a string then
string = [string stringByTrimmingCharactersInSet:[NSCharacterSet controlCharacterSet]];
NOTE: Removing all control characters will remove all new lines (\n
)!
From NSCharacterSet Class Reference:
These characters are specifically the Unicode values U+0000 to U+001F and U+007F to U+009F.
The value you are having a problem with is \x06
which is U+0006.
If you want to remove just \x06
, then you can always create a characters set just for it.
NSCharacterSet *hex6 = [NSCharacterSet characterSetWithCharactersInString:@"\x06"];
string = [[string componentsSeparatedByCharactersInSet:hex6] componentsJoinedByString:@""]