Empty String Literal

Flags uses of an empty string literal ("").

Remarks

Treating an empty string literal as equal to the 'vbNullString' constant requires using the PermissiveAssertClass. The default AssertClass is more strict about data types, and tells them apart.

Reasoning

Standard library constant 'vbNullString' is more explicit about its intent, and should be preferred to a string literal. While the memory gain is meaningless, an empty string literal still takes up 2 bytes of memory, but 'vbNullString' is a null string pointer, and doesn't. In VB6 and VBA this makes little to no difference however, but in earlier versions each instance of an empty string literal in source code resulted in the allocation of these 2 bytes every time.

Default severity

Warning

Inspection type

LanguageOpportunities

Examples

This example should trigger a result

MyModule (StandardModule)
Public Sub DoSomething(ByVal foo As String) If foo = "" Then ' ... End If End Sub

This example should NOT trigger a result

MyModule (StandardModule)
Public Sub DoSomething(ByVal foo As String) If foo = vbNullString Then ' ... End If End Sub

Rubberduck.CodeAnalysis.Inspections.Concrete.EmptyStringLiteralInspection.cs (Prerelease-v2.5.9.6289)