There is no method in the Visual Basic string class to find the number of lines in a multi-line string. However, with a little creative use of the existing methods, the value can still be discovered. The key is to note that the "vbNewLine" constant can be used as input for the "split" method. This will give you an array of all the lines in the string, and from there you need only to check the size of the array to see the string length in lines.
Open Visual Basic. Create a new project by clicking "File," "New Project." Select "Console application."
Paste the following code within the application:
Dim s = "This is a " & vbNewLine & " multiline string."
Dim t = s.Split(vbNewLine)
This defines a string with two lines, shows it to the user, splits it wherever there is a line break and shows you the total line count.
Click "Run" to test your application.
How to Convert a String to a Number in Visual Basic
Visual Basic (VB) is a programming language used to create desktop and website applications. One common part of VB programming is converting...
How to Find a Character in a String in VBA
Finding a single character in a string using VBA is a special instance of finding one string within another. The process itself...
How to Add a Line Break to a String
When writing a program, it is important to understand how to output readable text to the user. Many times, the programmer must...