Romain
Romain

Reputation: 91

How to initialise an NSMutableString to avoid \n when parsing an xml?

I have a little problem and i can not find how to solve it.

Actually, I parse an Xml file and when i pick up a value in a tag with the

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

I have as result : LABELLEDEXPIRYPG = "Janv 2015\n ";

As you can see there is "\n and some spaces behind "Janv 2015"

I initialise my NSMutableString simply : currentExpiry = [[NSMutableString alloc] init]; and i use apendString to set NSMutableString :

 if ([currentElement isEqualToString:kExpiry]){
        [currentExpiry appendString:string];
    } 

Please someone can help me to find a way to solve that ?

Thanks for all !

Upvotes: 0

Views: 121

Answers (1)

Kristian
Kristian

Reputation: 26

This one worked for me:

NSString *temp = [string stringByReplacingOccurrencesOfString:@"\n" withString:@"" options:0 range:NSMakeRange(0, 1)];

Or you can use this line: very useful in XML parser:

NSString *temp = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 

Upvotes: 1

Related Questions