0

ユーザーが入力するブラウザのテキストボックスがあります。入力した内容を改行で分割するために、次のことを試みています。次のことを試しましたが、うまくいきませんでした。エラーが発生するか、分割されません。

content.Split("\n", StringSplitOptions.None) < gives me an error Error The best overloaded method match for 'string.Split(params char[])' has some invalid arguments    

content.Split('\n', StringSplitOptions.None) < gives an error: The best overloaded method match for 'string.Split(params char[])' has some invalid arguments

content.Split(new[] { Environment.NewLine }, StringSplitOptions.None) < doesn't split as needed. When I look at the source in debugger I just see \n characters. 

content.Split(new[] { "\r\n" }, StringSplitOptions.None) < doesn't split as needed. When I look at the source in debugger I just see \n characters. 

誰かが私に何ができるか提案できますか?

4

1 に答える 1

2

content.Split正しく呼び出す:

content.Split(new [] { "\n" }, StringSplitOptions.None);
content.Split(new [] { '\n' }, StringSplitOptions.None);

Environment.NewLine3番目のオプションは「\n\ r」であるためWindows環境では機能しませんが、stingには「\n」しか含まれていません。

4番目のオプションでは、もう一度「\ n\r」を探します。

または、

content.Split(new [] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

これにより、「\r」と「\n」が分割され、空の行がすべて削除されます。

于 2012-10-05T15:35:19.017 に答える