I need to remove the white space only from the left of NSString I mean
if I have " This is a good day"
I will have "This is a good day"
only the left spaces only
any suggestion please
Just use
NSString* result = [yourString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
it will remove all extra space from left as well as right but not from middle
and to remove both white space and \n
use
NSString* result = [yourString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
Use below to remove white and new line chatacter from your NSString
.
NSString* result = [yourString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
Nsstring *str=" This is a good day";
while ([str rangeOfString:@" "].location != NSNotFound) {
str = [str stringByReplacingOccurrencesOfString:@" " withString:@" "];
}
nslog(@"string after removing space %@",)
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