By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,065 Members | 1,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,065 IT Pros & Developers. It's quick & easy.

only letters or numbers

P: n/a
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
Mar 26 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
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.
Mar 27 '06 #2

P: n/a
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

Mar 27 '06 #3

P: n/a
Hi,

Use a regular expression.

Dim regText As New System.Text.RegularExpressions.Regex("^[a-zA-Z0-9]+$ ")

Trace.WriteLine(regText.IsMatch("Los Angeles, CA"))


http://regexlib.com/Search.aspx?k=alphanumeric

Ken
---------------
"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
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

Mar 27 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.