繁体   English   中英

什么是PHP substr()的Ruby等价物?

[英]What is the Ruby equivalent of the PHP substr()?

什么是PHP语句的Ruby等价物

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

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

substring = bigstring[0,5]

我曾经推荐http://railsforphp.com/substr作为查找常见PHP函数的Ruby / Rails等效的好方法,但显然它不再在线。 那真不幸 :/

使用byteslice方法

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM