brewersfan1976

sum_up_numbers.rb

Jul 19th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.56 KB | None | 0 0
  1. def sumUpNumbers(inputString)
  2.     x = 0
  3.     string_length = inputString.length
  4.     number = ""
  5.     sum = 0
  6.    
  7.     while (x < string_length)
  8.           if inputString[x].to_s >= '0' and inputString[x].to_s <= '9' then
  9.              while (inputString[x].to_s >= '0' and inputString[x].to_s <= '9')    
  10.                    number = number + inputString[x]
  11.                    x = x + 1
  12.              end
  13.              
  14.              sum = sum + number.to_i
  15.          end
  16.              
  17.          x = x + 1
  18.          number = ""
  19.     end
  20.        
  21.     return sum
  22. end
Advertisement
Add Comment
Please, Sign In to add comment