Click here to Skip to main content
14,698,283 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Hi,

I have 2 textboxes and 1 button, I enter some sting in textbox like "pen" and also enter the related text in other textbox like "p". If I click the button then I want the output is 3 means location of "n".
Anybody help me how to write the code please?
Posted
Updated 13-Oct-10 2:02am
v2
Comments
DavidKiryazi 13-Oct-10 6:55am
   
what?

You enter the word "pen" then you enter the letter "p" and the output is 3 means location of "n"? where did the "n" come into it?

Also, indexers start at 0, so n is actually at index 2 :)
shakil0304003 13-Oct-10 9:52am
   
i also have same opinion like DavidKiryazi ;)

Try this:

string _text = text1.box;
int _location = text.IndexOf(@"n");



_location will contain the location of 'n'.
   
v4
Comments
#realJSOP 13-Oct-10 7:42am
   
I don't understand how this can be marked as the answer, yet have two 1-votes...
Abhinav S 13-Oct-10 7:51am
   
Yeah something for the CP team to think about.
shakil0304003 13-Oct-10 9:53am
   
i also have same opinion like John Simmons / outlaw programmer ;)
string str = TextBox1.Text;
int position = str.IndexOf(TextBox2.Text)+1;
Label1.Text = position.ToString();

use it u will get the result i used +1 as indexing starts from 0.
   

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