[英]What is the Ruby equivalent of the PHP substr()?
什么是PHP语句的Ruby等价物
<?php echo substr("abcdefghijklm", 0, 5); ?>
Use the bracket notation, with the same two arguments as for substr
. 使用括号表示法,使用与
substr
相同的两个参数。
substring = bigstring[0,5]
I used to recommend http://railsforphp.com/substr as a great way to find Ruby/Rails equivalents for common PHP functions, but apparently it's no longer online. 我曾经推荐http://railsforphp.com/substr作为查找常见PHP函数的Ruby / Rails等效的好方法,但显然它不再在线。 That's unfortunate :/
那真不幸 :/
Use byteslice
method 使用
byteslice
方法
"abcdefghijklm".byteslice(0, 5) => "abcde"
https://ruby-doc.org/core-2.2.0/String.html#method-i-byteslice https://ruby-doc.org/core-2.2.0/String.html#method-i-byteslice
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.