从用户输入值获取字符 [英] Get Characters from the User Input Value
问题描述
大家好,
我有一些问题,可能是合乎逻辑的,请帮助我,问题是,我有一个带有文本框和按钮的简单页面,实际上允许用户输入一些逗号分隔的数字(例如43,12 ,213,32,12).现在,在提交时,在后端,我应用了一些公式,其中减去和减去所需的更大和更低的值,或者换句话说,我想分别获得输入数字(一个接一个).
请帮助我,或者如果有更好的方法,请告诉我.
在ASP.NET页面上感谢
Hello Everyone,
I have Some problem, may be its logical, please help me, the problem is that, that I have a simple page with a Textbox and a Button, actually User''s are allowed to enter some comma separated numbers(like 43, 12, 213, 32, 12). Now, when submit, on the back end, I applied some formula in which the greater and lower value required to subtract or also in other words I want to get the input number separately(one by one).
Please Help me or if there is a better way so tell me.
Thanks
推荐答案
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
________
后面的代码
受保护的void Button1_Click(对象发送者,EventArgs e)
{
string [] numberArray = TextBox1.Text.ToString().Split('','');
for(int i = 0; i< numberArray.Length -1; i ++)
{
//这里的数字比较逻辑
}
}
________
code behind
protected void Button1_Click(object sender, EventArgs e)
{
string[] numberArray = TextBox1.Text.ToString().Split('','');
for(int i =0 ; i < numberArray.Length -1; i++)
{
// number compare logic here
}
}
穆斯塔法,
以下逻辑可能会对您有所帮助.
Hi Mustafa,
following logic might help you..
string textbox ="23,35,45,65,75";
string[] input = textbox.Split(',');
int length = input.Length;
int[] result = new int[length];
for(int i=0; i< length;i++)
result[i] = Convert.ToInt32(input[i]); ;
int difference = result.Max() - result.Min();
--SRJ
--SRJ
这篇关于从用户输入值获取字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!