C#文本框多行移动行数 [英] C# textbox multiline Line Count for mobile

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

问题描述

我想计算多行文本框中的行数.
线路不适用于移动设备.

任何想法都会有所帮助

谢谢


亲爱的里克·肖布
非常感谢.
对我有很大帮助.
效果很好.

这是用于符号扫描仪的,所以我必须为-1.
这就是我用来计算行数的内容,其中包括您的2行编码.
string [] lines = textBox1.Text.Split(''\ n'');
int numberOflines = lines.Length -1;
textBox2.Text = Convert.ToString(numberOflines);

I want to count lines in multi line TextBox for mobile.
Lines is not working with mobile.

Any idea will help

Thanks


Dear Rick Shaub
Thank you so much.
Big help to me.
It works fine.

This is for symbol scanner, so i have to -1.
This is what i used to count lines include your 2 lines of coding.
string[] lines = textBox1.Text.Split(''\n'');
int numberOflines = lines.Length -1;
textBox2.Text = Convert.ToString(numberOflines);

推荐答案

此外,更通用的解决方案是处理不同类型的换行符:
Also, a more general solution would be to handle different types of newlines:
int len = System.Text.RegularExpressions.Regex.Split("line1\r\nline2", @"\r?\n").Length;


或者,您可以使用另一个版本的string.Split:


Alternatively, you could use another version of string.Split:

int len = "line1\r\nline2".Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).Length;


您可以发布不起作用的代码吗?

如果您想要文本的行数,则可以使用类似以下内容的内容:

Can you post the code that''s not working?

If you want the number of lines of text you could just use something like:

string[] lines = textbox1.Text.Split(''\n'');
int numberOflines = lines.Length;



注意:我只会使用Split(''\ n''),因为我从未见过将'\ r'单独用作换行符.此外,Split(''\ n'')将相同地对待"\ n"和"\ r \ n".



Note: I''d just use Split(''\n'') because I''ve never seen ''\r'' use alone as a newline character. Additionally, Split(''\n'') will treat "\n" and "\r\n" identically.


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

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