Two practical ways to intercept strings (wrap more than a certain length), the code is as follows:
1/**////
2///intercept string, no Limit string length
3///
4///string to intercept
5///The length of each line, more than the length of line wrap
6///
7 public string Cutstr (string Str,int len)
8 {string s= "";
9
for (int i=0;i 11 {
int r= i% Len;
int last = (str. Length/len) *len;
if (i!=0 && i<=last)
15 {
16
if (r==0)
18 {
S+=str. Substring (I-len,len) + "
";
20}
21st
22}
Or else if (i>last)
24 {
S+=str. Substring (i-1);
-Break;
27}
28
29}
30
return s;
32
33}
34
35
36/**////
37///Intercept the string and limit the length of the string, more than the given length + ...
38///
39///String to intercept
40///The length of each line, more than the length of line wrap
41///Maximum length of output string
42///
The public string cutstr (string str,int len,int max)
44 {
s= string "";
sheng= string "";
The IF (str). Length >max)
48 {
Str=str. Substring (0,max);
Sheng= "";
51}
for (int i=0;i 53 {
The int r= i% len;
int last = (str. Length/len) *len;
if (i!=0 && i<=last)
57 {
58
The IF (r==0)
60 {
S+=str. Substring (I-len,len) + "
";
62}
63
64}
An else if (i>last)
66 {
S+=str. Substring (i-1);
a break;
69}
70
71}
72
S+sheng return;
74
75}