Click here to Skip to main content
14,880,764 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi to all,
can any one tell me how to count number of lines existed in text-box
Posted
Comments
anushripatil 10-Jan-12 2:35am
   
can you please elaborate a little, you want a multiline text box to show no. of characters or lines??

Run the below code.

C#
private static long CountLinesTextbox()
{
    string strText = TextBox1.Text;
    long count = 1;
    int start = 0;
    while ((start = strText.IndexOf('\n', start)) != -1)
    {
        count++;
        start++;
    }
    return count;
}
   
Comments
sahabiswarup 10-Jan-12 2:48am
   
great answer
5 from me.
keep answering
   
this might also help you to read all the lines in a textfile

VB
Dim oRead As System.IO.StreamReader
Dim FirstLine(1499) As String
oRead = IO.File.OpenText(Application.StartupPath & "\test.txt")
        Dim lineNo As Integer = 0
        While Not oRead.EndOfStream
            FirstLine(lineNo) = oRead.ReadLine
            lineNo += 1
        End While
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900