开发者

Is this the correct way to split a string using line breaks

I've written some code to take a word doc and copy it to the clipboard. In this word doc there is 800+ strings on their own line.

I'm trying to split the document by line, insert it into a list and then for testing purposes display one of the lines. However, I am getting an empty message box. (Previous 开发者_运维知识库tests show the list does indeed contain 800+ rows. They may just be null because of wrong code.)

Here's my code:

string myData = data.GetData(DataFormats.Text).ToString();

List<string> myList = new List<string>(myData.Split(new char[]{'\r','\n'}));

MessageBox.Show(myList[5]);

What am I doing wrong?


try

myData.Split(new string[]{Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜