Interesting .Net 4 thing of the day: String.IsNullOrWhiteSpace()
MSDN Library - String.IsNullOrWhiteSpace Method
“Indicates whether a specified string is Null reference (Nothing in Visual Basic), empty, or consists only of white-space characters.
…
IsNullOrWhiteSpace is a convenience method that is equivalent to calling the Trim() method followed by the IsNullOrEmpty method.
White-space characters are defined by the Unicode standard. The IsNullOrWhiteSpace method interprets any character that returns a value of true when it is passed to the Char.IsWhiteSpace method as a white-space
Module Example
Public Sub Main()
Dim values() As String = { Nothing, String.Empty, "ABCDE",
New String(" "c, 20), " " + vbTab + " ",
New String(ChrW(&h2000), 10) }
For Each value As String In values
Console.WriteLine(String.IsNullOrWhiteSpace(value))
Next
End Sub
End Module
' The example displays the following output:
' True
' True
' False
' True
' True
' True…”
I love seeing these kind of helper/convenience methods that we all write/re-invent get baked into .Net…
(via William Bartholomew - New Method: String.IsNullOrWhiteSpace() andalso This Week on Channel 9 - TWC9: Asli Bilgin, Halloween, VS2010, and community events)
No comments:
Post a Comment