What is the Ruby equivalent of PHP substr ()?
What is the Ruby equivalent of a PHP expression
<?php echo substr("abcdefghijklm", 0, 5); ?>
+7
Mithun sreedharan
source share2 answers
Use parenthesis notation with the same two arguments as for substr .
substring = bigstring[0,5] I usually recommended http://railsforphp.com/substr as a great way to find the Ruby / Rails equivalents for regular PHP functions, but it seems to no longer work online. This is unfortunate: /
+17
Matchu
source shareUse the byteslice method
"abcdefghijklm".byteslice(0, 5) => "abcde" https://ruby-doc.org/core-2.2.0/String.html#method-i-byteslice
0
Rahul patel
source share