brewersfan1976

insert_dashes.rb

Mar 8th, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.52 KB | None | 0 0
  1. def insertDashes(inputString)
  2.     array_length = inputString.length
  3.     x = 0
  4.     string = ""
  5.    
  6.     while (x < array_length)
  7.         if x == array_length - 1 then
  8.            string = string + inputString[x]
  9.            break
  10.         end  
  11.            
  12.         if inputString[x] != ' ' and inputString[x + 1] != ' ' then
  13.            string = string + inputString[x] + '-'
  14.         else
  15.            string = string + inputString[x]
  16.         end
  17.            
  18.         x = x + 1
  19.     end
  20.        
  21.     return string
  22. end
Advertisement
Add Comment
Please, Sign In to add comment