Get specific line - Printable Version +- BP Forums (https://bpforums.info) +-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55) +--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56) +---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8) +----- Forum: Programming Help (https://bpforums.info/forumdisplay.php?fid=9) +----- Thread: Get specific line (/showthread.php?tid=682) |
Get specific line - brco900033 - 10-24-2012 Hi all! I have a little question about how to read a line that contains for example "blabla", it's just a part of the text so no complete match. Thanks in advance! <!-- s8-) --><img src="{SMILIES_PATH}/icon_cool.gif" alt="8-)" title="Cool" /><!-- s8-) --> Re: Get specific line - brandonio21 - 10-24-2012 You sorta already have an answer in this thread: <!-- l --><a class="postlink-local" href="http://bpforums.info/viewtopic.php?f=9&t=645">viewtopic.php?f=9&t=645</a><!-- l --> If we just alter the code a little bit, we can get it to do exactly what you want! [code2=vbnet]Public Function ReadLine(ByVal containing As String) If (TextBox1.Text.Contains(containing)) Then 'Now, we need to find which line index contains the thing Dim lineIndex As Integer = TextBox1.GetLineFromCharIndex(TextBox1.Text.IndexOf(containing)) 'Now, let's return the line Dim lines As New List(Of String) lines.AddRange(TextBox1.Text.Split(vbNewLine)) Return lines.Item(lineIndex) End If End Sub[/code2] And there you go! Now to get the entire line, you can simply do something like this: [code2=vbnet]MsgBox(ReadLine("blabla"))[/code2] Re: Get specific line - brco900033 - 10-26-2012 Thanks man, appreciate your help! |