琴弦位置
问题描述:
我有2个文本框和1个按钮,我在文本框中输入了类似"pen"的字符串,还在其他文本框中输入了相关的文本,例如"p".如果单击按钮,则我希望输出为3表示位置"n".
有人帮我怎么写代码吗?
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?
答
尝试一下:
Try this:
string _text = text1.box;
int _location = text.IndexOf(@"n");
_location
将包含"n"的位置.
_location
will contain the location of ''n''.
字符串str = TextBox1.Text;
int position = str.IndexOf(TextBox2.Text)+1;
Label1.Text = position.ToString();
使用它,您将获得我使用+1的结果,因为索引从0开始.
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.