sql - Cleaning text strings in vb -


i trying clean string text field part of sql query.

i have created function:

private function cleanstringtopropercase(dirtystring string) string     dim cleanedstring string = dirtystring     'removes non alphanumeric characters except @, - , .'     cleanedstring = regex.replace(cleanedstring, "[^\w\.@-]", "")     'trims unecessary spaces off left , right'     cleanedstring = trim(cleanedstring)     'replaces double spaces single spaces'     cleanedstring = regex.replace(cleanedstring, "  ", " ")     'converts text upper case first letter in each word'     cleanedstring = strconv(cleanedstring, vbstrconv.propercase)      'return nicely cleaned string'     return cleanedstring end function 

but when try clean text 2 words, strips white space out. "daz's bike" becomes "dazsbike". assuming need modify following line:

   cleanedstring = regex.replace(cleanedstring, "[^\w\.@-]", "") 

so lets single white space characters remain. advice on how received cannot find on online tutorials or on msdn site (http://msdn.microsoft.com/en-us/library/844skk0h(v=vs.110).aspx)

use "[^\w\.,@\-\' ]" instead of pattern string.

also, use

regex.replace(cleanedstring, " +", " ") 

instead of

regex.replace(cleanedstring, "  ", " ") 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -