개발

[.net] 글자수 만큼 자르기

지승준 2013. 12. 31. 10:17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
protected void bindControl( object sender, RepeaterItemEventArgs e ) {
 
    if( e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item ) {
 
        Literal c_lt = new Literal();
 
        //데이터값 변수에 저장
        string nm = Cvt.String( DataBinder.Eval( e.Item.DataItem, "NM" ) );
        string phone = Cvt.String( DataBinder.Eval( e.Item.DataItem, "PHONE" ) );
        string new_phone = string.Empty;
 
        if( phone.IndexOf( "-" ) == -1 ) {
 
            forint i = 0, j = phone.Length; i < j; i++ ) {
 
                if( i == 3 ) new_phone += "-*";
                else if( i == 4 || i == 5 ) new_phone += "*";
                else if( i == 6 ) new_phone += "*-";
                else new_phone += phone[i];
 
            }
 
        } else {
 
            string[] phone_arr = phone.Split( '-' );
            phone_arr[1= "".PadLeft( phone_arr[1].Length, '*' );
            new_phone = String.Join( "-", phone_arr );
 
        }
 
        string new_nm = string.Empty;
        forint i = 0, j = nm.Length; i < j; i++ ) {
 
            if( i == 0 ) new_nm += nm[i];
            else if( j == 2 && ( i + 1 ) == j ) new_nm += "*";
            else if( ( i + 1 ) == j ) new_nm += nm[i];
            else new_nm += "*";
 
        }
 
        c_lt = ( Literal )e.Item.FindControl( "nm" );
        c_lt.Text = new_nm;
 
        c_lt = ( Literal )e.Item.FindControl( "phone" );
        c_lt.Text = new_phone;
 
    }
 
}
cs