Skip to content

Instantly share code, notes, and snippets.

@hpjaj
Created September 11, 2014 16:35
Show Gist options
  • Save hpjaj/33393c6a7160d1639c02 to your computer and use it in GitHub Desktop.
Save hpjaj/33393c6a7160d1639c02 to your computer and use it in GitHub Desktop.
1e_split_a_string.rb
s = "Welcome to the forum.\nHere you can learn Ruby.\nAlong with other members.\n"
def string_processor(non_split_string)
line_number = 0
split_into_sentences = non_split_string.split(/\n/)
split_into_sentences.each do |sentence|
sentence.prepend("Line " + (line_number += 1).to_s + ": " )
end
end
puts string_processor(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment