Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I have a string with a sentence. The string is displayed in a richtextbox. The user types a letter in a textbox and the program attempts to find that letter in the string. I want to make it that when the user presses a button a messagebox appears and displays the letter along with its numeric position in the string.

For example, if my sentence has 10 letters and the letter that the user types is number 5 how do I display that letter's number in the messagebox?

Thanks.
Posted
Updated 12-Jul-12 3:49am
v3
Comments
[no name] 12-Jul-12 9:20am    
Your question is not clear. You want to know how to write MessageBox.Show("5")?
MR. AngelMendez 12-Jul-12 9:36am    
I want to get a letter's line number and display it in the messagebox
[no name] 12-Jul-12 10:06am    
I do not think that is what you want either. What I *think* you want is: MessageBox.Show(yourstring.IndexOf(textbox.txt).ToString());
MR. AngelMendez 12-Jul-12 10:26am    
I followed the code that you put but I'm puzzled, what can I do with this?
[no name] 12-Jul-12 10:38am    
I am not sure what you are asking me here if you are asking me at all since you did not reply to me. What do you mean "what can I do with this?" It is the answer to your question. I cannot see your project, your code, your hard drive or read your mind. I would assume that you would write this into your code where you want to display the index of the letter in your string since that is what you asked to be able to do.

1 solution

Make a handler to the KeyPress event of the textbox. Then check out 'e.KeyChar'.
 
Share this answer
 
Comments
MR. AngelMendez 12-Jul-12 8:08am    
I'm sorry I was talking about the letters not the keychar. I updated my question so no one else will get confused. Thanks.

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