?
Solved

Regex return only letters

Posted on 2009-12-28
5
Medium Priority
?
265 Views
Last Modified: 2012-05-08
how can I return only  letters A-Z from a string using regex. if I have a string like "abcdef^&%0087" I only want . abcdef

C#
0
Comment
Question by:JonMny
  • 5
5 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 26132840
you could use RegEx replace...


replace all other characters that aren't chars with ""...
0
 
LVL 21

Expert Comment

by:silemone
ID: 26132864
string word ="";
word= myStr.Replace("[0-9](_&*?", "");
0
 
LVL 21

Accepted Solution

by:
silemone earned 2000 total points
ID: 26132871
something like that would take the original string and strip it of all other characters except letters...
0
 
LVL 21

Expert Comment

by:silemone
ID: 26133098
i know you gave me the points already, but this is the perfected version:

using using System.Text.RegularExpressions;
on my aspx page i have a text box - txt that the user inputs string to modify in...

you can just use strings in place of the text box...

basically says remove anything that is not alphabets - make everything else empty string - ""

 txt.Text = Regex.Replace(txt.Text.ToString(), @"[^a-zA-Z]", "");
0
 
LVL 21

Expert Comment

by:silemone
ID: 26133099
cheers..
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question