1

I'm new here. I just want to know how to remove all numbers from a textbox when a button is clicked. For example, if textbox has text hello1, when I click the button it should be hello.

Thanks.

user2442470
  • 143
  • 1
  • 2
  • 7

2 Answers2

3

Try this.

var output = Regex.Replace(textbox.Text, @"[\d-]","");
  • Hi sir. This is working perfectly. Can you please explain to me some of the code? Thank you. – user2442470 Jun 07 '13 at 05:32
  • The \d identifier simply matches any digit character.if your textbox have any digit number , it's replaced as empty! –  Jun 07 '13 at 05:33
  • 1
    That dash character may cause unwanted consequences. For example `"12 pseudo-codes"` -> `"pseudocodes"`. If the OP is only in interested in removing digits, I think `\d` would suffice. – Sina Iravanian Jun 07 '13 at 05:35
  • 1
    @user2442470 if this answer is helpful, then you can accept this answer by clicking tickmark besides this answer. :) – Freelancer Jun 07 '13 at 05:38
0
 textBox1.Text = new string(textBox1.Text.Where(t => t <= '0' || t >= '9').ToArray());

This will also do

Taj
  • 1,718
  • 1
  • 12
  • 16