Convert PHP code into Ruby!
RSS icon Email icon Home icon
  • ltrim

    Posted on June 16th, 2009 RubyLove No comments

    The ltrim function strips whitespace (or other characters) from the beginning of a string.

    PHP

    echo ltrim('John and I love icecream', 'John and ');
    => // 'I love icecream'

    Ruby

    substitute = 'John and ';
     
    puts "John and I love icecream".gsub(/^[#{substitute}]+/, '')
    => # 'I love icecream'

    Leave a reply