Removing Special Characters From a TextBox
How can one remove some special characters from a TextBox?
Assuming there is TextBox on a Windows Form and you have to enter a password , name, address etc.
If you wish that some some special characters such as comma(,), semicolen(;), plus (+) etc. be removed from the TextBox after, for example, you have clicked a button.Here's a little trick:
You enter in the TextBox for example "+Bo=n;d" and click button1.
The method:
private void button1_Click(object sender, System.EventArgs e) {
char[] trim = {'=', '\', ';','.', ':',',','+','*'}; //you can put here your chars
int pos;
while ((pos = this.textBox1.Text.IndexOfAny (trim)) >= 0)
{
this.textBox1.Text = this.textBox1.Text.Remove (pos, 1);
}//while
}
will be invoked andthe result of the new string without chars in string variable "trim" is displayed in the TextBox.
Download Source
H|seyin Altindag
haltindag@btopenworld.com












No comments yet... Be the first to leave a reply!