拆分Label中的文本

时间:2013-08-14 09:44:49

标签: c# split

我的文字非常长,有50个或更多的单词,我需要拆分ex:

string text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.;
if(Text.text.Length > 30)
string split = text.split(>30);
label1.text = split; (Lorem Ipsum is simply dummy text of the printing and typesetting industry..)

有可能吗?

4 个答案:

答案 0 :(得分:3)

if(Text.text.Length > 30)
  label1.text = string.Format("{0}...", label1.text.Substring(0, 30));

答案 1 :(得分:1)

label1.Text = (text.Length > 30) ? text.Substring(0, 30) + "..." : text;

答案 2 :(得分:0)

你看的是函数Substring over String class

text = text.Substring(0,30);

这会将text截断为长30个字符串。

答案 3 :(得分:0)

如果您只想要一个生成样本的程序化答案:

if (text.Length > 30)
{
    label1.Text = text.Remove(30) + "..";
}

或者,如果您只想修剪显示,如果您使用的是WPF,则应考虑使用TextBlock并设置TextTrimming属性而不是Label

2009年您可以查看一篇旧帖子,提供示例Label控件,提供文本修剪显示功能:http://blog.thekieners.com/2009/08/05/label-control-with-texttrimming/