i have a requirement where i have to read the textbox integer value and i have to append zeros to the field of the count entered in the textbox. for ex, user have entered as 3, then i have to read this value and append 3 zeros with the field. how to do this.?
please help me in achieving this ..
//TextBox1.Text = "4"; Assumed you enter 4
int txtValue = 0;
int.TryParse(TextBox1.Text.Trim(), out txtValue);
if (txtValue > 0)
{
for (int i = 0; i < txtValue; i++)
{
TextBox1.Text += "0";
}
}
//Result is 40000
abivenkat
Member
50 Points
97 Posts
reading an integer value in c#
May 28, 2012 08:25 AM|LINK
hi all,
i have a requirement where i have to read the textbox integer value and i have to append zeros to the field of the count entered in the textbox. for ex, user have entered as 3, then i have to read this value and append 3 zeros with the field. how to do this.? please help me in achieving this ..
thanks,
abivenkat
Krishna_Srid...
Member
638 Points
170 Posts
Re: reading an integer value in c#
May 28, 2012 08:32 AM|LINK
public string append()
{
int a = Convert.ToInt32(textbox1.text);
string output = "";
//Perform a for loop
(for int i = 1;i<=a;i++)
{
output = output + "0";
}
return output;
}
Call the append method to get the output you wanted
Krish
-I have not failed. I've just found 10,000 ways that won't work ! - Edison
kashifilyaz
Participant
1144 Points
198 Posts
Re: reading an integer value in c#
May 28, 2012 08:39 AM|LINK
//TextBox1.Text = "4"; Assumed you enter 4 int txtValue = 0; int.TryParse(TextBox1.Text.Trim(), out txtValue); if (txtValue > 0) { for (int i = 0; i < txtValue; i++) { TextBox1.Text += "0"; } } //Result is 40000Please let me know in case of any issue