title: Classic ASP InStr() Evaluates True on Empty Comparison String
body: <p>I ran into an issue with the Classic ASP VbScript <code>InStr()</code> function.  As shown below, the second call to <code>InStr()</code> returns <code>1</code> when searching for an empty string in a non empty string.  I'm curious why this is happening.</p>
  
  <pre><code>' InStr Test
  Dim someText : someText = "So say we all"
  Dim emptyString : emptyString = ""
  
  '' I expect this to be true
  If inStr(1,someText,"so",1) &gt; 0 Then
      Response.write ( "I found ""so""&lt;br /&gt;" )
  End If 
  
  '' I expect this to be false
  If inStr(1, someText, emptyString, 1) &gt; 0 Then
      Response.Write( "I found an empty string&lt;br /&gt;" )
  End If
  </code></pre>
  
  <p><strong>EDIT:</strong>
  Some additional clarification:  The reason for the question came up when debugging legacy code and running into a situation like this:</p>
  
  <pre><code>Function Go(value)
       If InStr(1, "Option1|Option2|Option3", value, 1) &gt; 0 Then
            ' Do some stuff
       End If
  End Function
  </code></pre>
  
  <p>In some cases function <code>Go()</code> can get called with an empty string.  The original developer's intent was not to check whether <code>value</code> was empty, but rather, whether or not <code>value</code> was equal to one of the piped delimited values (Option1,Option2, etc.).</p>
  
  <p>Thinking about this further it makes sense that every string is created from an empty string, and I can understand why a programming language would assume a string with all characters removed still contains the empty string.</p>
  
  <p>What doesn't make sense to me is why programming languages are implementing this.  Consider these 2 statements:</p>
  
  <pre><code>InStr("so say we all", "s") '' evaluates to 1
  InStr("so say we all", "")  '' evaluates to 1
  </code></pre>
  
  <p>The <code>InStr()</code> function will return the position of the first occurrence of one string within another. In both of the above cases, the result is 1.  However, position 1 always contains the character "s", not an empty string.  Furthermore, using another string function like Len() or LenB() on an empty string alone will result in 0, indicating a character length of 0.</p>
  
  <p>It seems that there is some inconsistency here.  The empty string contained in all strings is not actually a character, but the InStr() function is treating it as one when other string functions are not.  I find this to be un-intuitive and un-necessary.</p>