C#:string判空

1.  string.IsNullOrEmpty (str)    

.Net 2 可用,也就是 Unity 能用

str = “”    ---> true

str = “ ”   ---> false

str = null  ---> true

 

2. String.IsNullOrWhiteSpace(str)  

namespace为:System.String

.Net 4 可用,也就是 Unity 不能用

本质上相当于:string.IsNullOrEmpty(value) || value.Trim().Length == 0;

 

 

str = ""    ---> true

 

str = "   "  ---> true

 

str = null  ---> true

 

posted @ 2017-06-16 12:27  MakeBetter  阅读(1457)  评论(0编辑  收藏  举报