Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ユーザーがNSString入力したテキストで構成されるがありますUITextView。その結果、文字列には、文字列内の改行文字とともに、先頭と末尾の改行文字が含まれる場合があります(Returnキーを押して新しい行を入力した場合)。文字列内の文字列をそのままにして、文字列の最初と最後から改行文字を削除したいと思います。
NSString
UITextView
これについて行くための最良の方法は何でしょうか?
text = [text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
これにより、空白も削除されます。空白を保持したい場合は、newlineCharacterSet代わりに使用してください。
newlineCharacterSet
@ghettopiaに従って、作成する代わりにnewlineCharacterSetを使用することについての正しい提案に従って編集しました。カスタムのもの。