Asp.net| Tips | string
Two practical ways to intercept strings (wrap more than a certain length)
1/**////<summary>
2///intercept string, no Limit string length
3///</summary>
4///<param name= "str" > string to intercept </param>
5///<param name= "len" > length of each line, more than this length of automatic line wrap </param>
6///<returns></returns>
7 public string Cutstr (string Str,int len)
8 {string s= "";
9
for (int i=0;i<str. Length; 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) + "<br>";
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
/**////<summary>
37///Intercept the string and limit the length of the string, more than the given length + ...
///</summary>
///<param name= "str" > the string to be intercepted </param>
///<param name= "len" > length of each line, more than this length automatic line wrap </param>
///<param name= "Max" > Output string Maximum length </param>
///<returns></returns>
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}
The for (int i=0;i<str. Length; 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) + "<br>";
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}