代码之家  ›  专栏  ›  技术社区  ›  Mithun Sreedharan Kuldeep Modi

php substr()的ruby等价物是什么?

  •  7
  • Mithun Sreedharan Kuldeep Modi  · 技术社区  · 15 年前

    PHP语句的ruby等价物是什么

    <?php echo substr("abcdefghijklm", 0, 5); ?>

    2 回复  |  直到 9 年前
        1
  •  17
  •   Matchu    13 年前

    使用括号表示法,使用与for相同的两个参数 substr

    substring = bigstring[0,5]
    

    我曾经推荐 http://railsforphp.com/substr 作为一种寻找通用PHP函数的Ruby/Rails等价物的好方法,但显然它不再在线。很不幸:/

        2
  •  0
  •   Rahul Patel    9 年前

    使用 byteslice 方法

    "abcdefghijklm".byteslice(0, 5) => "abcde"
    

    https://ruby-doc.org/core-2.2.0/String.html#method-i-byteslice

    推荐文章