vb.net Code:
''' <summary>
''' Gets a single line from some text.
''' </summary>
''' <param name="text">
''' The original text.
''' </param>
''' <param name="index">
''' The zero-based index of the line to return.
''' </param>
''' <returns>
''' A <b>String</b> containing the specified line if it exists; otherwise, a null reference (<b>Nothing</b> in Visual Basic).
''' </returns>
''' <remarks>
''' The text is split preferentially on CR-LF pairs but also splits on lone LFs.
''' </remarks>
Private Function GetLine(text As String, index As Integer) As String
Return text.Split({ControlChars.CrLf, ControlChars.Lf},
StringSplitOptions.None).
Skip(index).
FirstOrDefault()
End Function
If the specified line is empty then that will return String.Empty while if the specified line doesn't exists, e.g. the text contains two lines and you specify 10 as the index, it will return Nothing. That could also be implemented as an extension method and called directly on any String.