Ruby Basic string operatiors


SUBMITTED BY: Guest

DATE: May 21, 2015, 2:05 p.m.

FORMAT: Ruby

SIZE: 445 Bytes

HITS: 742

  1. Example-001: String Length
  2. puts 'That is an object'.size # => prints 17
  3. Example-002: Reversing
  4. puts 'This is not a palindrome'.reverse # => prints 'emordnilap a ton si sihT'
  5. Example-003: Single substitution
  6. puts 'a banana'.sub('a', '*') # => prints '* banana'
  7. Example-004: Global substitution
  8. puts 'a banana'.gsub('a', '*') # => prints '* b*n*n*'

comments powered by Disqus