Hi there,
I wonder if any can help me on the following problem.
I have an integer of int iValue = 123;
I'd like to trip this integer into 3 small integers: int iValue1 = 1, int iValue2 = 2, int iValue3 = 3;
anyone have any idea how to do this.
thanks
Loading
VulpesPosted Mar 6, 2012, 5:19 AM
int iValue = 123;
string s = iValue.ToString();
int value1 = s[0] - 48;
int value2 = s[1] - 48;
int value3 = s[2] - 48;
Jignesh TrivediPosted Mar 5, 2012, 11:27 PM
you have two way.
int value = 123;
1st way
int value1 = value / 100;
int value2 = (value - value1 * 100) / 10;
int value3 = value - (value1 * 100) - (value2 * 10);
2nd way
int value11 = Convert.ToInt32(value.ToString().Substring(0, 1));
int value22 = Convert.ToInt32(value.ToString().Substring(1, 1));
int value33 = Convert.ToInt32(value.ToString().Substring(2, 1));
hope this help.