2013-08-14 2 views
0

의 텍스트 내가 매우 매우 긴 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..) 

이 가능합니까? 당신이 보는 무엇

+0

문자열을 변경해야하나요? 라벨에 [너무 긴 텍스트 줄 바꿈] (http://stackoverflow.com/questions/1204804/word-wrap-for-label-in-winforms)을 사용 하시겠습니까? –

+0

변경 사항 만 바꿈 없음) = 변경 사항 split.Replace ("...", "."); – Federal09

+0

텍스트가 가변적이어서 문자열 대체를 사용할 수 없습니다. – Federal09

답변

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

이는 text (30)에 문자열 길이를 자릅니다 String 클래스

text = text.Substring(0,30);

이상 기능 부분 문자열입니다.

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

당신은 당신의 샘플을 생성하는 프로그램 대답하려면 : 당신은 그냥 디스플레이 트리밍하려는 경우 당신이 TextBlock 사용을 고려하여 설정해야 WPF를 사용하는 경우, 또는

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

Label 대신 TextTrimming 속성을 사용하십시오.

2009 년 이전 게시물에는 텍스트 자르기 표시 기능을 제공하는 샘플 Label 컨트롤이 제공됩니다 (http://blog.thekieners.com/2009/08/05/label-control-with-texttrimming/).