how to insert character between the string

Asked By Reena Jain
09-Feb-10 02:21 PM
Earn up to 0 extra points for answering this tough question.
Hi,

I am using windows application. for eg i have a label having following string:-

http://reena.india.yahoo.com and in any text box if i put sport then immediately
text should become (even on keypress) http://sport.reena.india.yahoo.com or
http://www.sport.reena.india.yahoo.com. even space should replace with _ (underscore).

How it should done. i need to use only keypress. keyup or keydown event
not leave event. I want as user enter the value it should show him immidiately,
because i am using windows application. i only want the example of windows application, since previous answer in not working for me

thanks in advance

  Are you aware

[)ia6l0 iii replied to Reena Jain
09-Feb-10 02:47 PM
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.

  re: how to insert character between the string

Santhosh N replied to Reena Jain
10-Feb-10 01:06 AM
I suppose you are looking to show the items from soemwhere (may be collection or DB and while it matches any word in keypress event like autosuggest

then you can have some logic timer and keypress together and poll the results taking the entered value from textbox and query the collection or DB and implement replace method there and display in the label or textbox...
Create New Account