XTab's Blog

Ged Mead's Blog at vbCity

This blog hosted by:
http://blogs.vbcity.com      
  Home :: Syndication  :: Login

JunJuly 2008Aug
SMTWTFS
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

Archives

Topics

Ramblings

VB.NET

    As Bilbo Baggins desperately tried to guess while on his adventures in The Hobbit, the answer to “What’s it got in his pocketses”   -   “String ...… or Nothing   “  (which was really two guesses).

 

    I came across another example of one of those relatively small improvements in VB2005 this week.    It won’t send your productivity zooming but it’s still nice to see these little tweaks that all add up to an overall improvement of the language.

 

   There previously has been – and still is – a ReadOnly member of the String Class called Empty.   The usage is:-

 

Dim s As String

'  Some other code

If s = String.Empty Then  ' Do something

 

   On the same lines, there previously has been – and still is – the IsNothing function available in the Microsoft.VisualBasic namespace.

 

If Not IsNothing(d) Then  ' Do something

  

   The new tweak I mentioned combines both of the above tests and combines them into one new method in the String class  -  IsNullOrEmpty.

 

 

It’s a Shared function that returns a Boolean value, so the syntax is:

 

If String.IsNullOrEmpty(s) Then   ' Do Something

(where s is a String variable)

 

 

And the kind of scenario where you will get a result of True includes:

 

Dim s As String  ' Default value is empty string

s = Nothing  '  Explicitly set to Nothing

s = "" ' Explicitly set to an empty string

 

   Might come in handy one day .     Now,  where did I put that ring ......

posted on Thursday, April 06, 2006 4:05 AM