Remove part of string between two strings
In below sample i have removed string between two angular
brackets i.e. between < & >
I want the strings between the angular brackets so,
-(void) FetchString
{
NSString *descriptionString = @"<hi this is> Suraj <and this is my> blog";
NSString *outputString = [self removeNodesFromXMLString: descriptionString ];
NSLog(@"outputString is :- %@", outputString);
}
-(NSString *)
removeNodesFromXMLString: (NSString *)
descriptionString
{
NSMutableString *resultString = [descriptionString
mutableCopy];
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:@"\\<.+?\\>"
options:NSRegularExpressionCaseInsensitive
error:NULL];
[regex replaceMatchesInString:resultString
options:0
range:NSMakeRange(0, [resultString length])
withTemplate:@"
"];
return resultString;
}
When my FetchString method is executed i will get log:
outputString is :-Suraj blog
and that's it i am done.
Comments
Post a Comment