mercredi 6 mai 2015

Replace only single occurrence of \n or \r in NSSTring

I am reading text from a PDF to NSString. I replace all the spaces using the code below

NSString *pdfString = convertPDF(path);
    pdfString=[pdfString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    pdfString=[pdfString stringByReplacingOccurrencesOfString:@"\r" withString:@""];
    pdfString=[pdfString stringByReplacingOccurrencesOfString:@"\n" withString:@""];

But this also eliminates paragraph spaces and multiple lines. I want to replace only a single occurrence of \n or \r and retain the paragraph spaces or multiple tabs and next lines.

Aucun commentaire:

Enregistrer un commentaire