开发者

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

开发者 https://www.devze.com 2023-02-19 15:31 出处:网络
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'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

精彩评论

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

关注公众号