对于选定行中的每一行(vb.net)
我如何才能获得其中包含选定文本的行? 例如: 选定的行将是1、2、3和4。0是第一行 我怎样才能获得如下代码:对于选定行中的每一行(vb.net),.net,vb.net,textbox,lines,selected,.net,Vb.net,Textbox,Lines,Selected,我如何才能获得其中包含选定文本的行? 例如: 选定的行将是1、2、3和4。0是第一行 我怎样才能获得如下代码: For Each line as string(or integer) in textbox1."SelectedLines" 'Do something here for each line Next 谢谢我想您正在查找SelectedText属性。 在C中 在我尝试VB时 Dim splitter(1) As String splitter(0) = Envir
For Each line as string(or integer) in textbox1."SelectedLines"
'Do something here for each line
Next
谢谢我想您正在查找SelectedText属性。 在C中 在我尝试VB时
Dim splitter(1) As String
splitter(0) = Environment.NewLine
For Each y As String In TextBox1.SelectedText.Split(splitter, StringSplitOptions.RemoveEmptyEntries)
//do stuff here
Next
从字面上讲,您需要找到行号,即使只选择了第1行和第4行的一部分。按以下步骤进行:
If RichTextBox1.SelectionLength > 0 Then
Dim firstLine As Integer = RichTextBox1.GetLineFromCharIndex(RichTextBox1.SelectionStart)
Dim lastLine As Integer = RichTextBox1.GetLineFromCharIndex(RichTextBox1.SelectionStart + RichTextBox1.SelectionLength)
For line As Integer = firstLine To lastLine
Dim txt = RichTextBox1.Lines(line)
' do something...
Next
End If
仅供参考-如果这是问题所问的-这些相同的方法也可以在常规的文本框控件上使用。谢谢,我在询问后意识到我需要行号,但谢谢s_hewitt的其他答案
If RichTextBox1.SelectionLength > 0 Then
Dim firstLine As Integer = RichTextBox1.GetLineFromCharIndex(RichTextBox1.SelectionStart)
Dim lastLine As Integer = RichTextBox1.GetLineFromCharIndex(RichTextBox1.SelectionStart + RichTextBox1.SelectionLength)
For line As Integer = firstLine To lastLine
Dim txt = RichTextBox1.Lines(line)
' do something...
Next
End If