Click to See Complete Forum and Search --> : How can I insert a string in target cursor?


hikki
March 28th, 2003, 03:49 AM
Hi, everybody..
How can I insert a text into a string randomly...

e.g. there a string "Hello, Friend" in the textbox.

If I move a cursor within "Hello," and "Friend",
can I insert a text "Dear" immediately within the string?

How to do that? any function can get the cursor position within a String????

Thanks for your help.

pareshgh
March 28th, 2003, 11:54 AM
for example you can use Insert, take the IndexOf etc..
string has lots of methods in it.

string s = "Hello, Friend";
s = s.Insert(6,"Dear");
MessageBox.Show(s);

Paresh

hikki
March 28th, 2003, 07:09 PM
Thank you Paresh,

Actaully, I know this insert method,

But I want to know where is the cursor position within the string, so that I can use .insert(position,string)....

hikki

wolfofthenorth
March 28th, 2003, 08:06 PM
If you want the position of the caret in the textbox... try

textBox1.SelectionStart

hikki
March 28th, 2003, 08:13 PM
oh good...
unbelievable !!

Thanks a lot... wolfofthenorth.

wolfofthenorth
March 28th, 2003, 08:22 PM
Glad I could help. :)

pareshgh
March 31st, 2003, 10:31 AM
you will need to look more in Richtextbox, the members are sufficient for your basic needs of selection and insertion.
you will also need to look in string members and methods.

Paresh