XML Literals: Simplifying Strings
Fri, Jul 3 2009 10:51
You have probably heard that the next version of VB will no longer require line continuation characters in most situations. This is very good news for those of us that do not like typing underscore characters.
But in the mean time, what do we do if we have a long string, like a SQL string:
Dim mySelect As String = "Select CustomerId, " & _
"LastName, " & _
"FirstName, " & _
"EmailAddress " & _
"From Customer " & _
"Where CustomerId = @CustomerID"
And this one is only selecting three fields!
XML Literals can help:
Dim mySelect2 As XElement = <string>
Where CustomerId = @CustomerId
Notice in the XML literals example that there are no quotes, ampersands (&) or underscores (_). That can save a lot of typing and it is easier to read.
Since mySelect2 is an XElement, use the Value property to get the string from the element.