title: Cleaning text strings in vb
body: <p>I am trying to clean up a string from a text field that will be part of sql query.</p>
  
  <p>I have created a function:</p>
  
  
  
  <pre class="lang-vb prettyprint-override"><code>Private Function cleanStringToProperCase(dirtyString As String) As String
      Dim cleanedString As String = dirtyString
      'removes all but non alphanumeric characters except @, - and .'
      cleanedString = Regex.Replace(cleanedString, "[^\w\.@-]", "")
      'trims unecessary spaces off left and right'
      cleanedString = Trim(cleanedString)
      'replaces double spaces with single spaces'
      cleanedString = Regex.Replace(cleanedString, "  ", " ")
      'converts text to upper case for first letter in each word'
      cleanedString = StrConv(cleanedString, VbStrConv.ProperCase)
  
      'return the nicely cleaned string'
      Return cleanedString
  End Function
  </code></pre>
  
  <p>But when I try to clean any text with two words, it strips ALL white space out.  "daz's bike" becomes "Dazsbike".  I am assuming I need to modify the following line:</p>
  
  <pre class="lang-vb prettyprint-override"><code>   cleanedString = Regex.Replace(cleanedString, "[^\w\.@-]", "")
  </code></pre>
  
  <p>so that it also lets single white space characters remain.  Advice on how to do so is greatly received as I cannot find it on any online tutorials or on the MSDN site (<a href="http://msdn.microsoft.com/en-us/library/844skk0h(v=vs.110).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/844skk0h(v=vs.110).aspx</a>)</p>