728x90
반응형
-
출처 : http://www.codeproject.com/cs/samples/linenumberingapp.asp
-
c#
public void ConvertText() { StringBuilder output = new StringBuilder(); try { char[] end_of_line = {(char)10}; string[] lines = this.Text.Split( end_of_line ); int line_count = lines.GetUpperBound(0)+1; int linenumber_max_width = line_count.ToString().Length; string padding = new String( ' ', this.LineNumberPaddingWidth); for ( int i=0; i<line_count; i++ ) { output.Append( this.GetFormattedLineNumber( i+1, linenumber_max_width, padding ) ); output.Append( lines[i] ); output.Append( "\r\n" ); } if ( this.ConvertTabsToSpaces ) { string spaces = new String( ' ', this.TabToSpacesWidth); output = output.Replace( "\t", spaces ); } } catch ( Exception e ) { output.Append( e.Message ); } this.Text = output.ToString(); }
728x90
반응형
'C# .Net' 카테고리의 다른 글
C# 기본 값(primitive type)의 자동 초기화 (0) | 2024.08.28 |
---|---|
C#과 .NET 버전(version) (0) | 2024.08.28 |
C# 버전(version) (0) | 2024.08.28 |
c# ref 예제 (0) | 2007.06.19 |
C# 난수 (Random Number) (0) | 2007.04.09 |