Advertisement
eandmir

SumInAString

Jan 27th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using System;
  2.  
  3. class SumInAString
  4. {
  5.     static void Main()
  6.     {
  7.         string digitString = "1 11  111 ";
  8.         string tempSting = "",ch="";
  9.         int count = 0;
  10.  
  11.         for (int i = 0; i < digitString.Length; i++)
  12.         {
  13.             ch = digitString.Substring(i, 1);
  14.             if (ch != " ")
  15.             {
  16.                 tempSting += ch;
  17.             }
  18.             else if (ch == " " && tempSting != "")
  19.             {
  20.                 count += int.Parse(tempSting);
  21.                 tempSting = "";
  22.             }
  23.             if (i == digitString.Length - 1 && tempSting != "")
  24.             {
  25.                 count += int.Parse(tempSting);
  26.             }
  27.         }
  28.         Console.WriteLine(count);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement