0

オンライン ファイルから読み込まれたテキストを含む NSMutableString* (theBigString) があります。私は theBigString を iPad のローカル ファイルに書き込み、それを添付ファイルとして電子メールで送信しています。

[theBigString appendString:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]];

次のコード行を使用して最善を尽くしましたが、電子メールの添付ファイルを開くと、期待した (そしてアプリが動作するために必要な) 1 行の長いテキストではなく、複数行のテキストがまだ存在します。

[theBigString stringByReplacingOccurrencesOfString:@"\\s+" withString:@" "];
[theBigString stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
[theBigString stringByReplacingOccurrencesOfString:@"\r" withString:@" "];
[theBigString stringByReplacingOccurrencesOfString:@"\r\n" withString:@" "];

テキスト ファイルを開いて書式を表示すると、いくつかの新しい段落記号が表示されます。

「\n」または「\r」以外に、上記のコードで削除していない別の改行タイプの文字はありますか?

4

1 に答える 1

1

NSCharacterSet defines [NSCharacterSet newLineCharacterSet] as (U+000A–U+000D, U+0085)

If you don't care too much about efficiency, you could also just separate the string into an array at the newline character locations and combine it again with empty strings.

NSArray* stringComponents = [theBigString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
theBigString = [stringComponents componentsJoinedByString:@""];
于 2014-07-27T19:24:43.913 に答える