在 VB.net 中逐行读取文本框的最佳方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3320826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:57:46  来源:igfitidea点击:

Best way to read a textbox line by line in VB.net

vb.nettextboxinput

提问by Eugene

What's the best way to read in a the contents of a textbox line by line in VB.net 2.0?

在 VB.net 2.0 中逐行读取文本框内容的最佳方法是什么?

I'm currently using the one listed at TextBoxBase.Lines Property at MSDNbut wanted to know what other ways could one read in a textbox line by line in VB.net.

我目前正在使用MSDN 的 TextBoxBase.Lines 属性中列出的方法,但想知道在 VB.net 中逐行读取文本框的其他方法。

回答by David Brunelle

It might not be the best way, but you could always use TextBox.Text.Split(vbNewLine), which will return an array of string. You could use that in a for each loop

这可能不是最好的方法,但您始终可以使用 TextBox.Text.Split(vbNewLine),它会返回一个字符串数组。您可以在 for each 循环中使用它

For Each strLine As String In TextBox.Text.Split(vbNewLine)
...
Next

回答by Hans Passant

The Lines property is what you want to use. Parsing the Text property yourself requires more code and doesn't make it faster. Write a better question if you have a reason to look for an alternative.

Lines 属性是您要使用的属性。自己解析 Text 属性需要更多的代码并且不会使其更快。如果您有理由寻找替代方案,请写一个更好的问题。