VB.Net – Count lines of a string


To totally unlock this section you need to Log-in


Login

Sometimes it could be useful to check if a specified string (long, usually) is constructed as a single line or not. To check this aspect of our text string we could use the following approach:

MessageBox.Show(examplestring.Split(vbCrLf).Length)

This is saying "show me a messagebox (so we can view the answer) where we take "examplestring" split it on the delimiter vbCrLf and tell us how many pieces we get (the length of the array). Now if the last line has a vbCrLf as well, this may report an extra number of lines because the last line would be seen as blank.