rubystringfunctioncharsubstr

Ruby - How to select some characters from string


I am trying to find a function for select e.g. first 100 chars of the string. In PHP, there exists the substr function

Does Ruby have some similar function?


Solution

  • Try foo[0...100], any range will do. Ranges can also go negative. It is well explained in the documentation of Ruby.