0

我的文本非常长,包含 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

4 回答 4

3
if(Text.text.Length > 30)
  label1.text = string.Format("{0}...", label1.text.Substring(0, 30));
于 2013-08-14T09:49:13.700 回答
1
label1.Text = (text.Length > 30) ? text.Substring(0, 30) + "..." : text;
于 2013-08-14T09:52:22.827 回答
0

你看到的是函数 Substring over String 类

text = text.Substring(0,30);

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

于 2013-08-14T09:51:04.627 回答
0

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

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

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

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

于 2013-08-14T09:53:13.483 回答