📄 asp_net 字符串操作基类(安全,替换,分解等) --喜欢就打开.mht
字号:
bsp; =20
{<BR> &n=
bsp; =20
break;<BR> &nb=
sp; =20
}<BR> =20
}<BR> =20
//=E5=A6=82=E6=9E=9C=E6=88=AA=E8=BF=87=E5=88=99=E5=8A=A0=E4=B8=8A=E5=8D=8A=
=E4=B8=AA=E7=9C=81=E7=95=A5=E5=8F=B7<BR> &nb=
sp; =20
byte[] mybyte =3D=20
System.Text.Encoding.Default.GetBytes(strInput);<BR> &nb=
sp; =20
if (mybyte.Length >=20
intlen)<BR> &n=
bsp;=20
{<BR> &n=
bsp; =20
strString +=3D=20
"=E2=80=A6";<BR> &nb=
sp; =20
}<BR> =
return=20
strString;<BR> =20
}<BR> #endregion</P>
<P> #region=20
=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=88=86=E5=87=BD=E6=95=B0<BR> &nb=
sp; ///=20
<summary><BR> ///=20
=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=88=86=E5=87=BD=E6=95=B0<BR> &nb=
sp; ///=20
</summary><BR> /// =
<param=20
name=3D"strID"></param><BR> &=
nbsp; ///=20
<param=20
name=3D"index"></param><BR> &=
nbsp; ///=20
<param=20
name=3D"Separ"></param><BR> &=
nbsp; ///=20
<returns></returns><BR> &n=
bsp;=20
public string StringSplit(string strings, int index, string=20
Separ)<BR> =20
{<BR> =
string[]=20
s =3D=20
strings.Split(char.Parse(Separ));<BR> =
=20
return s[index];<BR> =20
}<BR>#endregion</P>
<P> #region=20
=E5=88=86=E8=A7=A3=E5=AD=97=E7=AC=A6=E4=B8=B2=E4=B8=BA=E6=95=B0=E7=BB=84<=
BR> ///=20
<summary><BR> ///=20
=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=88=86=E5=87=BD=E6=95=B0<BR> &nb=
sp; ///=20
</summary><BR> /// =
<param=20
name=3D"str">=E8=A6=81=E5=88=86=E8=A7=A3=E7=9A=84=E5=AD=97=E7=AC=A6=E4=
=B8=B2</param><BR> =20
/// <param=20
name=3D"splitstr">=E5=88=86=E5=89=B2=E7=AC=A6,=E5=8F=AF=E4=BB=A5=E4=B8=
=BAstring=E7=B1=BB=E5=9E=8B</param><BR> &nbs=
p; =20
///=20
<returns>=E5=AD=97=E7=AC=A6=E6=95=B0=E7=BB=84</returns><BR>&n=
bsp; =20
public static string[] splitstr(string str, string=20
splitstr)<BR> =20
{<BR> =
if=20
(splitstr !=3D=20
"")<BR> =
=20
{<BR> &n=
bsp; =20
System.Collections.ArrayList c =3D new=20
System.Collections.ArrayList();<BR> &n=
bsp; =20
while=20
(true)<BR> &nb=
sp; =20
{<BR> &n=
bsp; =20
int thissplitindex =3D=20
str.IndexOf(splitstr);<BR>  =
; =20
if (thissplitindex >=3D=20
0)<BR> &=
nbsp; =20
{<BR> &n=
bsp; =20
c.Add(str.Substring(0,=20
thissplitindex));<BR> &nbs=
p;  =
; =20
str =3D str.Substring(thissplitindex +=20
splitstr.Length);<BR> &nbs=
p; =20
}<BR> &n=
bsp; =20
else<BR>  =
; =20
{<BR> &n=
bsp; =20
c.Add(str);<BR> &nbs=
p;  =
; =20
break;<BR> &nb=
sp; =20
}<BR> &n=
bsp; =20
}<BR> &n=
bsp; =20
string[] d =3D new=20
string[c.Count];<BR>  =
; =20
for (int i =3D 0; i < c.Count;=20
i++)<BR>  =
; =20
{<BR> &n=
bsp; =20
d[i] =3D=20
c[i].ToString();<BR>  =
; =20
}<BR> &n=
bsp; =20
return =
d;<BR> =
}<BR> =20
else<BR>  =
;=20
{<BR> &n=
bsp; =20
return new string[] { str=20
};<BR> =
}<BR> =20
}<BR> #endregion</P>
<P> #region=20
URL=E7=BC=96=E7=A0=81<BR> ///=20
<summary><BR> ///=20
URL=E7=BC=96=E7=A0=81<BR> ///=20
</summary><BR> /// =
<param=20
name=3D"str">=E5=AD=97=E7=AC=A6=E4=B8=B2</param><BR> =
=20
///=20
<returns></returns><BR> &n=
bsp;=20
public static string UrlEncoding(string=20
str)<BR> =20
{<BR> =
byte[]=20
bytes =3D=20
System.Text.Encoding.UTF8.GetBytes(str);<BR>  =
; =20
return=20
System.Text.Encoding.UTF8.GetString(bytes).ToString();<BR> &nb=
sp; =20
}<BR> #endregion</P>
<P> #region=20
=E8=8E=B7=E5=8F=96Web.config=E4=B8=AD=E7=9A=84=E9=85=8D=E7=BD=AE=E5=AD=97=
=E6=AE=B5=E5=80=BC<BR> ///=20
<summary><BR> ///=20
=E8=8E=B7=E5=8F=96=E5=85=A8=E5=B1=80=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0<=
BR> ///=20
</summary><BR> /// =
<param=20
name=3D"key">=E9=94=AE=E5=90=8D</param><BR> &nb=
sp; ///=20
<returns>=E5=8F=82=E6=95=B0</returns><BR> &n=
bsp; =20
public static string GetApp(string=20
key)<BR> =20
{<BR> =20
System.Configuration.AppSettingsReader appr =3D new=20
System.Configuration.AppSettingsReader();<BR> &nbs=
p; =20
try<BR> =
=20
{<BR> &n=
bsp; =20
string str =3D (string)appr.GetValue(key,=20
typeof(string));<BR>  =
; =20
if (str =3D=3D null || str =3D=3D "") return=20
null;<BR> &nbs=
p; =20
return=20
str;<BR>  =
;=20
}<BR> =
catch=20
(Exception E) {=20
}<BR> =
return=20
null;<BR> }</P>
<P> #endregion</P>
<P> #region=20
=E6=A0=B9=E6=8D=AE=E4=BC=A0=E5=85=A5=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=
=98=AF=E5=90=A6=E4=B8=BAyes/no=E8=BF=94=E5=9B=9EBit<BR> =
///=20
<summary><BR> ///=20
=E6=A0=B9=E6=8D=AE=E4=BC=A0=E5=85=A5=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=
=98=AF=E5=90=A6=E4=B8=BAyes/no=E8=BF=94=E5=9B=9EBit<BR> =
///=20
</summary><BR> /// =
<param=20
name=3D"flg"></param><BR> &nb=
sp; ///=20
<returns></returns><BR> &n=
bsp;=20
public static int GetBitBool(string=20
flg)<BR> =20
{<BR> =
int str=20
=3D =
0;<BR> =
switch=20
(flg.ToLower())<BR> =
=20
{=20
<BR> &nb=
sp; =20
case=20
"yes":<BR> &nb=
sp; =20
str =3D=20
1;<BR> &=
nbsp; =20
break;<BR> &nb=
sp; =20
case"no":<BR> =
=20
str =3D=20
0;<BR> &=
nbsp; =20
break;<BR> &nb=
sp; =20
default:<BR> &=
nbsp; =20
break;<BR> &nb=
sp;=20
}<BR> =
return=20
str;<BR> =20
}<BR> #endregion</P>
<P> #region=20
Html=E7=BC=96=E7=A0=81<BR> /// =
<summary><BR> ///=20
HTML=E7=BC=96=E7=A0=81<BR> /// =
</summary><BR> /// =
<param=20
name=3D"strInput"></param><BR> &nbs=
p; =20
///=20
<returns></returns><BR> &n=
bsp;=20
public static string HtmlEncode(string=20
strInput)<BR> =20
{<BR> =
string=20
str;<BR>  =
;=20
try<BR> =
=20
{<BR> &n=
bsp; =20
str =3D=20
HttpContext.Current.Server.HtmlEncode(strInput);<BR> &nb=
sp; =20
}<BR> =20
catch<BR> &nbs=
p;=20
{<BR> &n=
bsp; =20
str =3D=20
"error";<BR> &=
nbsp;=20
}<BR> =
return=20
str;<BR> =20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -