From: Joe Van Dyk Date: 2005-09-24T10:29:25+09:00 Subject: Re: trimming strings On 9/23/05, jotto wrote: > folks-> > > i am using RoR's scaffolding for a very basic blog setup. > > I want to trim the string for the text that comes with each entry in > the database. Ideally I want to trim it where it first finds
. I > imagine I use a loop to count how many characters I get to before it > finds
? Then I use some function (a function I can't find) that > trims the string to the desired amount of characters. Your question is sort of unclear. So I'm not really sure what you're asking for. But perhaps the following will help you: str = "some very long string that has lots of text in it.
" str << "more long boring text that has lots of text in it.
" puts "The string contains: '#{ str }'" puts puts "Number of characters before first
tag: " puts str.split("
").first.length puts puts "Trimming to 30 characters: " puts str[0..30] OUTPUTS The string contains: 'some very long string that has lots of text in it.
m ore long boring text that has lots of text in it.
' Number of characters before first
tag: 51 Trimming to 30 characters: some very long string that has