0

I have a text very very long with 50 or more words and i need to split 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..)

it is possible?

Federal09
  • 639
  • 4
  • 9
  • 25

4 Answers4

3
if(Text.text.Length > 30)
  label1.text = string.Format("{0}...", label1.text.Substring(0, 30));
Damith
  • 62,401
  • 13
  • 102
  • 153
1
label1.Text = (text.Length > 30) ? text.Substring(0, 30) + "..." : text;
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
chris vietor
  • 2,050
  • 1
  • 20
  • 29
0

What you look is function Substring over String class

text = text.Substring(0,30);

This will truncate the text into 30 character string long.

0

If you just want a programmatic answer that generates your sample:

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

Alternatively, if you just want trimming for display, if you are using WPF you should consider using a TextBlock and set the TextTrimming property instead of a Label.

There's an old post from 2009 you could look at that provides sample Label control that provides text trimming display functionality: http://blog.thekieners.com/2009/08/05/label-control-with-texttrimming/.

Nick Bauer
  • 1,027
  • 8
  • 13