计算文本框中的总行数 [英] Count Total lines in a textbox

查看:98
本文介绍了计算文本框中的总行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
任何人都可以告诉我如何计算文本框中存在的行数吗?

Hi to all,
can any one tell me how to count number of lines existed in text-box

推荐答案

运行以下代码.

Run the below code.

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;
}


Count Number of Lines in TextArea (Textbox) With Word Wrap [^] should help you out.


这也可以帮助您阅读所有内容文本文件中的行

this might also help you to read all the lines in a textfile

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


这篇关于计算文本框中的总行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆