the KeyPress event as stated earlier would be invoked on every key press and would create a nuisance
and not solve your problem?
The easiest way is to use String.Replace. On the underscore, do a Replace again after concatenation.
Like,
string finalString = originalstring.Replace("http://", "http://www.").Replace(" " , "_");
You should perhaps do this on TextBox Lost Focus Or perhaps the Leave Event
private void textBox1_Leave(object sender, EventArgs e)
{
string originalString = textBox1.Text.Trim();
if (!string.IsNullOrEmpty(originalString )
{
textBox1.Text = originalstring.Replace("http://", "http://www.").Replace(" " , "_");
}
}
Hope that helps.