Return index of all occurrences of a character in a string in ruby
ruby, string
Solution
s = "a#asg#sdfg#d##"
a = (0 ... s.length).find_all { |i| s[i,1] == '#' }
Problem
I am trying to return the index's to all occurrences of a specific character in a string using Ruby. A example string is `"a#asg#sdfg#d##"` and the expected return is `[1,5,10,12,13]` when searching for `#` characters. The following code does the job but there must be a simpler way of doing this? ``` def occurances (line) index = 0 all_index = [] line.each_byte do |x| if x == '#'[0] then all_index << index end index += 1 end all_index end ```