i've been searching high and low for a method that will help me do this for
a couple of days, but decided eventually just to post here in the hope
someone can point out the probably blatantly obvious for me
i'm looking for something that can take a string and truncate it to a
certain amount of characters. then i can add '...' at the end.
i've been searching high and low for a method that will help me do this for
a couple of days, but decided eventually just to post here in the hope
someone can point out the probably blatantly obvious for me
i'm looking for something that can take a string and truncate it to a
certain amount of characters. then i can add '...' at the end.
s = 'abcdefghijklmnopqrstuvwxyz'
puts s[0, 6] << '...'
aaaah. i see. is this another case of 'everything is an object'? i need to
wrap my head around the all pervasiveness of what that means in the future.
thanks all.
"Florian Gro脽" <florgro@gmail.com> wrote in message
news:danghf$l0b$1@sea.gmane.org...
路路路
luke wrote:
> i'm looking for something that can take a string and truncate it to a
> certain amount of characters. then i can add '...' at the end.
>
> i used to use substr() when working with php
>
> $str = substr( $str, 0, 200) . "...";
The most correct way of doing this IMHO is this:
str += "..." if str.slice!(200 .. -1)
which will cut away everything after the first 200 characters and append
a marker if the string was truncated.
aaaah. i see. is this another case of 'everything is an object'? i need to
wrap my head around the all pervasiveness of what that means in the future.
thanks all.
"blah".class #=> String
From the command line:
ri String#
ri String#concat
ri String#slice!
Generally,
ri String
Devin
路路路
The most correct way of doing this IMHO is this:
str += "..." if str.slice!(200 .. -1)
which will cut away everything after the first 200 characters and append
a marker if the string was truncated.