2016/09/12(Mon) 23:44:30 編集(投稿者)
■No81378 (riiiya さん) に返信
こんな感じかしら
void test()
{
String value = "1+1";
int left = 0;
int right = 0;
char operatorName = '\0';
for (int i = 0; i < value.Length; i++)
{
if (char.IsNumber(value, i))
{
if (i == 0)
{
left = int.Parse(value[i].ToString());
}
else if (i == 2)
{
right = int.Parse(value[i].ToString());
}
}
else if (i == 1)
{
operatorName = value[i];
}
}
int result = calculate(left, right, operatorName);
}
int calculate(int left, int right, char operatorName)
{
if (operatorName == '+')
{
return left + right;
}
else
{
return 0;
}
}