I have a string say \"Allentown, pa\"
How to remove the white space in between ,
and pa
using objective c?
Swift 3:
var word: String = "Hello world"
let removeWhiteSpace = word.stringByRemovingWhitespaces
word = "Helloworld"
myStr = [myStr stringByReplacingOccurrencesOfString:@" " withString:@""];
In my case NSString was added Zero Width Space(i i used some library). so solution worked for me.
NSMutableString *newString=[[newString stringByReplacingOccurrencesOfString:@"\u200B" withString:@""] mutableCopy];
@"\u200B" is Zero width space character value.
you can use remove function to remove any substring from the string
- (NSString*)remove:(NSString*)textToRemove fromString:(NSString*)input {
return [input stringByReplacingOccurrencesOfString:textToRemove withString:@""];
}
This will remove all space from myString
.
NSString *newString = [myString stringByReplacingOccurrencesOfString:@" " withString:@""];
I have tried all the solutions here, none of them could remove the whitespace generated by the Chinese PinYin Input method.
After some debugging, I found this working:
NSString *newString = [myString stringByReplacingOccurrencesOfString:@"\342\200\206" withString:@""];
I have googled what the '\342\200\206' is, but failed.
Whatever, it works for me.