1. 程式人生 > >轉載:string.IsNullOrEmpty和string.IsNullOrWhiteSpace方法的區別

轉載:string.IsNullOrEmpty和string.IsNullOrWhiteSpace方法的區別

char ace length string pty div isn 如果 使用

string.IsNullOrEmpty():判斷字符串是否為null或者為string.Empty,如果是"\t"這樣的字符就返回false,為了達到判斷過濾這些功能,就要使用Trim()和Length屬性幫忙,判斷是否長度為零 string.IsNullOrWhiteSpace():判斷所有空白字符,相當於string.IsNullOrEmpty和str.Trim().Length總和,他將字符串給Char.IsWhiteSpace為ture的任何字符都將是正確的(推薦使用)

轉載:string.IsNullOrEmpty和string.IsNullOrWhiteSpace方法的區別