C# 在标签中拆分文本

C# 在标签中拆分文本,c#,split,C#,Split,我的文本非常长,包含50个或更多单词,我需要拆分: 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 scramb

我的文本非常长,包含50个或更多单词,我需要拆分:

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..)

有可能吗?

您看到的是字符串类上的函数子字符串

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


这将把
文本
截断为30个字符长的字符串。

您看到的是字符串类上的函数子字符串

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


这将把
文本
截断为30个字符长的字符串。

如果您只需要生成示例的编程答案:

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

可选地,如果您只想进行显示修剪,如果使用WPF,则应考虑使用“代码>文本块,并设置<代码>文本修剪< /COD>属性,而不是<代码>标签< /> > < /P>


2009年的一篇老文章提供了示例标签控件,该控件提供文本修剪显示功能:。

如果您只需要生成示例的编程答案:

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

可选地,如果您只想进行显示修剪,如果使用WPF,则应考虑使用“代码>文本块,并设置<代码>文本修剪< /COD>属性,而不是<代码>标签< /> > < /P>


2009年的一篇老文章提供了一个标签控件示例,该控件提供了文本修剪显示功能:。

您需要更改字符串还是要更改标签中的字符串?仅换行不更改=)对于更改,我使用split.Replace(“…”,”);文本是可变的,无法使用字符串替换是否需要更改字符串或是否要在标签中更改?仅包装无更改=)对于更改,我使用split.Replace(“…”,”);文本是可变的,无法使用字符串替换