From: Michael Neumann Date: 2003-11-19T09:33:00+09:00 Subject: Re: String startswith/endswith in Ruby? On Wed, Nov 19, 2003 at 08:52:18AM +0900, Dave Benjamin wrote: > Hi all, > > I'm a Python user trying to learn a bit of Ruby. I was wondering if there's > a common way of writing "startswith" and "endswith" expressions for strings > in Ruby. > > For instance: > > s = 'Hello, world!' > s.startswith('Hello') >> true > s.endswith('!') >> true > s.endswith('asdf') >> false Regular expressions are your friend: s =~ /^Hello/ s =~ /!$/ s =~ /asdf$/ Regards, Michael