On 9/23/05, jotto <jonathan.otto / gmail.com> 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 <br />. I
> imagine I use a loop to count how many characters I get to before it
> finds <br />? 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. <br />"
str << "more long boring text that has lots of text in it. <br />"

puts "The string contains: '#{ str }'"
puts
puts "Number of characters before first <br /> tag: "
puts str.split("<br />").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. <br />m
ore long boring text that has lots of text in it. <br />'

Number of characters before first <br /> tag:
51

Trimming to 30 characters:
some very long string that has