2009-08-15 8 views
0

Je la chaîne suivante ....manipulation de chaînes iphone

Overall: 21 (1,192,742<img src="/images/image/move_up.gif" title="+7195865" alt="Up" />)<br /> 
August: 21 (1,192,742<img src="/images/image/move_up.gif" title="+722865" alt="Up" />)<br /> 

Je dois enlever la balise HTML, est-il un moyen que je peux dire enlever tout entre ???

+0

Quelle est la chaîne exacte que vous voulez obtenir? Voulez-vous supprimer tout ce qui est entre les chevrons du texte entier? –

+0

Avez-vous réussi à résoudre ce problème? –

Répondre

1

Êtes-vous SOUHAITANT supprimer tous le contenu HTML de votre chaîne? Si oui, vous pouvez l'approcher de la manière suivante:

- (void)removeHtml:(NSString *) yourString 
{ 
    NSString *identifiedHtml = nil; 

    //Create a new scanner object using your string to parse 
    NSScanner *scanner = [NSScanner scannerWithString: yourString]; 

    while (NO == [scanner isAtEnd]) 
    { 

     // find opening html tag 
     [scanner scanUpToString: @"<" intoString:NULL] ; 

     // find closing html tag - store html tag in identifiedHtml variable 
     [scanner scanUpToString: @">" intoString: &identifiedHtml] ; 

     // use identifiedHtml variable to search and replace with a space 
     NSString yourString = 
       [yourString stringByReplacingOccurrencesOfString: 
          [ NSString stringWithFormat: @"%@>", identifiedHtml] 
          withString: @" "]; 

    } 
    //Log your html-less string 
    NSLog(@"%@", yourString); 
} 
0

Je ne sais pas si cela fonctionnera sur l'iPhone (parce que initWithHTML: documentAttributes: est un ajout AppKit) mais je l'ai testé pour une application Cocoa

NSString *text = "your posted html string here";   
NSData *data = [text dataUsingEncoding: NSUnicodeStringEncoding]; 
NSAttributedString *str = 
    [[[NSAttributedString alloc] initWithHTML: data documentAttributes: nil] autorelease]; 
NSString *strippedString = [str string]; 
+0

http://stackoverflow.com/questions/729135/why-no-nsattributedstring-on-the-iphone semblerait indiquer que vous ne pouvez pas l'utiliser sur l'iPhone –