String Manipulation

  • Thread starter Thread starter Aaron
  • Start date Start date
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
 
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.
 
Here's VB code for removing non-alphas:

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