Let's assume I have the string
NSString* myString = @"Hello,";
How can I remove the comma without leaving a space? I have tried:
NSString* newString = [myString stringByReplacingOccurrencesOfString:@"," withString:@""];
and
NSString* newString = [myString stringByTrimmingCharactersInSet:[NSCharacterSet punctuationCharacterSet]];
But both are leaving spaces.
This will escape double quotes in NSString: NSString *escaped = [originalString stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior.
I just ran the following as a test
NSString * myString = @"Hello,"; NSString * newString = [myString stringByReplacingOccurrencesOfString:@"," withString:@""]; NSLog(@"%@xx",newString);
And I get 2010-04-05 18:51:18.885 TestString[6823:a0f] Helloxx
as output. There is no space left.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With