通过新行 VB.NET 拆分字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14992920/
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-17 12:26:23  来源:igfitidea点击:

Splitting String by New Line VB.NET

vb.net

提问by y--

I'm writing a program that needs to split text in a RichTextBox by a new line. I've tried

我正在编写一个程序,需要通过新行拆分 RichTextBox 中的文本。我试过了

For Each Line As String In RichTextBox1.Text.Split(vbNewLine)

For Each Line As String In RichTextBox1.Text.Split(vbNewLine)

And I've tried

我试过了

For Each Line As String In RichTextBox1.Text.Split(System.Enviroment.NewLine)

For Each Line As String In RichTextBox1.Text.Split(System.Enviroment.NewLine)

Neither are working. It works if there's only one line of text but not after that. Any suggestions?

两者都没有工作。如果只有一行文本,但在那之后就不行了。有什么建议?

回答by Jsm

I guess the easiest way to do it is to use RichTextBox.Lines like so

我想最简单的方法是像这样使用 RichTextBox.Lines

For Each Line As String In RichTextBox1.Lines
    ' Do whatever
Next

Not sure why splitting by Environment.NewLine didn't work for you though, it worked fine for me when I just tested.

不知道为什么通过 Environment.NewLine 拆分对你不起作用,当我刚刚测试时它对我来说很好。

Edit: Just noticed the comment on the question, oops. That'll teach me for being slow with posting.

编辑:刚刚注意到对该问题的评论,哎呀。这将教会我发帖缓慢。