Saturday, 14 July 2012

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        
    [regex replaceMatchesInString:resultString
                            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.

No comments:

Post a Comment