ruby pastebin

Posted by Anonymous on Sat 11th Jun 15:26 (modification of post by view diff)
download | new post

  1. str ="Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."
  2. substr = "qui dolorem"
  3. offset = 2
  4.  
  5. def get_x_words(num, str, from_start = true)
  6.   splitted = str.split(' ')
  7.   unless from_start
  8.     splitted.reverse!
  9.     return splitted.slice(0,num).reverse.join(' ')
  10.   end
  11.   return splitted.slice(0,num).join(' ')
  12. end
  13.  
  14. if str.include? substr
  15.   _s = str.split(substr)
  16.   puts get_x_words(offset, _s[0], false) + substr.center(substr.length + 2,' ') + get_x_words(offset,_s[1], true)
  17. end

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


I'm Human
Remember me



Captcha required for posting