String Manipulation

A

Aaron

1. How do I remove non-alphanumeric characters?
Input: dEFD&*fdff/df;
output: dEFDfdffdf

2. How can I capitalize the first character of a word?
Input: remember
Output: Remember

Thanks
 
D

Dave Davidson

Check out Regular Expressions - they rock! I don't have
my reference material here, so I can't give you the exact
code, but you can use Regular Expressions to do either
one of these tasks in one, maybe two, lines of code. The
first task would be something like strText =
strTest.replace(/[^a-zA-Z0-9]/g, "") in JavaScript and
something very similar in VB.NET or C#. (Also, I think
there's a shortcut for [^a-zA-Z0-9] that refers to
alphanumeric characters.) Use the symbol for a Word
Boundary on your second task.
 
D

Dave Davidson

Here's VB code for removing non-alphas:

strStuff = System.Text.RegularExpressions.Regex.Replace
(strStuff, "^.*[^A-Za-z0-9].*$", "")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top