在字符串中获得某数字位置时,可以使用string类的IndexOf方法,该方法用来确定指定字符在字符串中的索引,如果在字符串中能找到指定字符,则返回其索引,否则返回-1。在字符串中获得数字位置的关键代码如下:string str = textBox1.Text.Trim();
int index = str.IndexOf(textBox2.Text.Trim());
if (index >= 0)
MessageBox.Show("数字" + textBox2.Text + "在字符串中的位置为:" + (index+1), "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("没有要查找的数字", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
相关文章:
-
2022-12-23
-
2021-12-05
-
2022-12-23
-
2022-12-23
-
2021-09-06
-
2021-11-20
-
2022-12-23
-
2022-02-01
猜你喜欢
-
2021-07-05
-
2021-11-26
-
2021-06-13
-
2021-11-21
-
2022-12-23
-
2022-12-23
-
2022-12-23
相关资源
-
下载
2021-06-06
-
下载
2022-12-01
-
下载
2023-04-02