Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I failed a bit before when I asked for help... here is JF2015 code:

string strInsertBefore = "<a>";
string strInsertAfter = "</a>";

string text = textBox4.Text.Substring(textBox4.SelectionStart, textBox4.SelectionLength);
text = strInsertBefore + text + strInsertAfter;


and I add this:
textBox4.Text = textBox4.Text.Insert(textBox4.SelectionStart, text);


this results in
<a>hello</a>hello

when I mark 'hello'. Do you know why I get double 'hello'?
Posted
Updated 14-Nov-10 4:30am
v3
Comments
shakil0304003 14-Nov-10 10:22am    
do not repost a question. If you want to add some thing, you can add it to the previous one.
euhiemf 14-Nov-10 12:09pm    
it was a server failure. so i can't add it to the previous one....!?

1 solution

Because you are inserting the text into the existing text, rather than replacing the old text with the new text.

Try
C#
textBox4.Text.Insert(textBox4.SelectionStart, strInsertBefore);
textBox4.Text.Insert(textBox4.SelectionStart + textBox4.SelectionLength - 1, strInsertAfter);


instead
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900