I was coding this app and was stuck with
removing the spaces from NSString
when i ran into this class called as NSRegularExpression and guess what i helped me a lot, given below is the code which i used to remove white spaces between NSString object hope it helpsRemove white spaces between NSString code :
NSString *whitespaceString = @"This is a string with white spaces ";
NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@" +" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *trimmedString = [regex stringByReplacingMatchesInString:whitespaceString options:0 range:NSMakeRange(0, [whitespaceString length]) withTemplate:@" "];
NSLog(@"%@",trimmedString);
Final String = This is a string with white spaces
Happy iCoding and have a great day....
Excelent i liked.
ReplyDeleteThanks for the hint and the lovely meme...love it :)
ReplyDeletethank's
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteNSString *whitespaceString = @"This is a string with white spaces ";
ReplyDeletewhitespaceString = [whitespaceString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
while ([whitespaceString rangeOfString:@" "].location != NSNotFound)
whitespaceString = [whitespaceString stringByReplacingOccurrencesOfString:@" " withString:@" "];
NSLog(@"%@", whitespaceString);
Really amazing blog, I’d love to discover some extra information. Epikone
ReplyDeleteVery informative blog, Finally i got good solutions for Remove white spaces between NSString..
ReplyDelete