Two practical methods for string truncation (automatic line feed beyond a certain length)
1 /**////
2 // intercept a string without specifying the length of the string
3 ///
4 // the string to be intercepted
5 // The length of each line, more than the length of this line automatically wrap
6 ///
7 public string CutStr (string str, int len)
8 {string s = "";
9
10 for (int I = 0; I 11 {
12 int r = I % len;
13 int last = (str. Length/len) * len;
14 if (I! = 0 & I <= last)
15 {
16
17 if (r = 0)
18 {
19 s + = str. Substring (I-len, len) +"
";
20}
21
22}
23 else if (I> last)
24 {
25 s + = str. Substring (I-1 );
26 break;
27}
28
29}
30
31 return s;
32
33}
34
35
36 /**////
37 // capture the string and limit the length of the string, more than the given length +...
38 ///
39 // the string to be truncated
40 // The length of each line.
41 // Maximum length of the output string
42 ///
43 public string CutStr (string str, int len, int max)
44 {
45 string s = "";
46 string sheng = "";
47 if (str. Length> max)
48 {
49 str = str. Substring (0, max );
50 sheng = "";
51}
52 for (int I = 0; I 53 {
54 int r = I % len;
55 int last = (str. Length/len) * len;
56 if (I! = 0 & I <= last)
57 {
58
59 if (r = 0)
60 {
61 s + = str. Substring (I-len, len) +"
";
62}
63
64}
65 else if (I> last)
66 {
67 s + = str. Substring (I-1 );
68 break;
69}
70
71}
72
73 return s + sheng;
74
75}