2010-06-30 7 views
0

Dans mon application, je suis en train de lire une page HTML dans une chaîne. HTML Page contient de nombreux tags, de nouvelles lignes & beaucoup d'autres caractères.Comment NSLog avec n r t

<style type="text/css"> 
    h3{ 
     font-weight:bold; 
     line-height:18px; 
     font-family:Arial; 
     font-size:12px; 
     text-align:justify; 
     color:black; 
     background-color:transparent; 
     width:280px; 
     margin:0; 
    } 

    body{ 
     font-weight:normal; 
     line-height:18px; 
     font-family:Arial; 
     font-size:12px; 
     text-align:justify; 
     color:black; 
     background-color:transparent; 
     width:280px; 
    } 
</style> 

Je souhaite remplacer cette chaîne comme suit. Lorsque nous NSLog ci-dessus page HTML, il va imprimer comme ci-dessus ressemble. Mais ce que je veux NSLog est comme suit

\t\t<style type="text/css">\n\t\t\th3{\n 
     font-weight:bold; 
     line-height:18px; 
     font-family:Arial; 
     font-size:12px; 
     text-align:justify; 
     color:black; 
     background-color:transparent; 
     width:280px; 
     margin:0; 
    } 

    body{ 
     font-weight:normal; 
     line-height:18px; 
     font-family:Arial; 
     font-size:12px; 
     text-align:justify; 
     color:black; 
     background-color:transparent; 
     width:280px; 
    } 
</style> 

Je veux dire y compris les caractères antislash. C'est possible? La raison derrière cela - Je veux remplacer le style ci-dessus dynamiquement - mais pour remplacer ci-dessus, je dois avoir une source à remplacer - Comment obtenir la source, y compris \ n & \ r caractères?

Répondre

4

Regardez le NSString reference. Vous aurez besoin de quelque chose comme:

string = [oldString stringByReplacingOccurrencesofString: @"\n" withString: @"\\n"]; 
// repeat for \t and \r 
Questions connexes