only letters or numbers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,

given a string, if i only wanted to get only letters and number (no symbols)
is there a function to do this?
i.e.
"Los Angeles, CA"
i don't want the comma.

thanks,
rodchar
 
given a string, if i only wanted to get only letters and number (no
symbols)
is there a function to do this?
i.e.
"Los Angeles, CA"
i don't want the comma.

Function CleanInput(strIn As String) As String
' Replace invalid characters with empty strings.
Return Regex.Replace(strIn, "[^\w\.@-]", "")
End Function

You can use
Return Regex.Replace(strIn, ",", "")
if that's all you need.
 
The easy way:

Dim s as string = strIn.Replace(",", "")

or the relatively easy way:

Dim strOut as string = ""
for each c as char in strIn.ToCharArray()
if char.IsLetterOrDigit(c) then
strOut &= c.ToString()
end if
next.

Either way, YOU WIN!

SN
 
Back
Top