会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Wind-Eagle
No pain,no gain!
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
公告
有关string和Cookie的几个有用的扩展方法
Posted on
2008-12-04 18:35
Andrew Yin
阅读(
252
) 评论(
0
)
收藏
举报
几个有用的扩展方法:
Code
public
static
bool
IsNullOrTrimEmpty(
this
string
value)
{
return
value
==
null
||
value.Trim().Length
==
0
;
}
public
static
bool
IsNullOrTrimEmpty(
this
HttpCookie cookie)
{
return
cookie
==
null
||
cookie.Value
==
null
||
cookie.Value.Trim().Length
==
0
;
}
public
static
int
ParseInt(
this
HttpCookie cookie)
{
int
tmpInt;
return
!
cookie.IsNullOrTrimEmpty()
&&
Int32.TryParse(cookie.Value.Trim(),
out
tmpInt)
?
tmpInt :
-
1
;
}
public
static
int
ParseInt(
this
string
strValue)
{
int
tmpInt;
return
Int32.TryParse(strValue,
out
tmpInt)
?
tmpInt :
-
1
;
}
public
static
string
ParseString(
this
HttpCookie cookie)
{
return
!
cookie.IsNullOrTrimEmpty()
?
cookie.Value.Trim() :
string
.Empty;
}
刷新页面
返回顶部
博客园
© 2004-2025
浙公网安备 33010602011771号
浙ICP备2021040463号-3