10. The text is given. Determine the sum of the numbers in the text.
using System;
namespace Test
{
class NumbersTest
{
static int Main()
{
string str = Console.ReadLine();
string buffer = "";
foreach (char c in str)
{
buffer += (Char.IsNumber(c) || c == '-') ? c : ' ';
}
string[] arr = buffer.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
int sum = 0;
foreach (string s in arr)
{
sum += int.Parse(s);
}
Console.WriteLine("The sum of the numbers is {0}", sum);
return 0;
}
}
}
Comments
Leave a comment