琴弦位置 [英] String position

查看:67
本文介绍了琴弦位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有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.


这篇关于琴弦位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆