0

私はこのようなこの2つの段落を持っています

On Friday afternoon after you leave work, you probably
think about going out and having a few drinks with 
friends to relax and wind down.  Even though you 
may think you deserve to go out and have a few drinks,
there are some things that you should certainly keep
in mind.

Like any other day, tomorrow is going to be a day
for exercise, and since you are exercising on a 
regular basis, a few drinks of alcohol won't really
hurt anything, right?  Before you decide to rush out
to the local bar, there are a few things below that
you should think about before you make your choice
about going out to drink some alcohol.

これにフォーマットするにはどうすればよいですか:

On Friday afternoon after you leave work, you probably think about going out and having a few drinks with friends to relax and wind down. Even though you may think you deserve to go out and have a few drinks, there are some things that you should certainly keep in mind.

Like any other day, tomorrow is going to be a day for exercise, and since you are exercising on a regular basis, a few drinks of alcohol won't really hurt anything, right? Before you decide to rush out to the local bar, there are a few things below that you should think about before you make your choice about going out to drink some alcohol.

次のように \n をスペースに置き換える方法しか知りません。

stringByReplacingOccurrencesOfString:@"\n" withString:@" "

しかし、各段落を認識する方法がわかりません

ありがとうございます

4

2 に答える 2

2

このコードは防弾ではなく、余分な改行文字をクリーンアップするために追加のコードが必要ですが、それはあなたを始めるのに役立つはずです:

// Assuming your input string contains all the text, then:

NSArray *paragraphs = [input componentsSeparatedByString:@"\n\n"];
for (NSString *paragraph in paragraphs)
{
    NSString *cleaned = [paragraph stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
    NSLog(@"paragraph = %@", cleaned);
}
于 2013-02-14T15:52:35.830 に答える
1

2 つの連続する「\n\n」を検索します。これにより、それが段落であることがわかります。

于 2013-02-14T15:47:29.320 に答える