如何仅从组合框项目中获取整数值 [英] How to fetch only integer values from combobox items
本文介绍了如何仅从组合框项目中获取整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
comboBox1.Items.Add("1秒");
comboBox1.Items.Add("2秒");
已添加到组合框.
1)如果我从组合框选择1秒,则应在文本框中显示1.只要我能做到这一点.
2)另一种基于文本框的文本,例如1如何获取combox项
并显示选定的项目
comboBox1.Items.Add(" 1 second");
comboBox1.Items.Add("2 second");
added to combobox .
1)if i select 1 second from combobox .1 should be displayed in textbox provided how can i do this .
2) Another based on textbox text such as 1 how can i fetch combox items
and display the selected item
推荐答案
许多选项之一:查找正则表达式匹配为[[0-9] +];阅读System.Text.RegularExpressions.Regex
上的帮助以获取说明.
-SA
One of many options: find Regex match of "[0-9]+"; read the help onSystem.Text.RegularExpressions.Regex
for instructions.
—SA
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string[] splitted = comboBox1.Text.Split(' ');
if (splitted.Length > 1)
textBox1.Text = splitted[0];
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textbox1.text=comboBox1.Text.Split('' '')[0];
}
这篇关于如何仅从组合框项目中获取整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文