Forum: Ruby on Rails count("<p>") in a string

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7007cea0aa8f62646493ac4b50ae0641?d=identicon&s=25 klaas (Guest)
on 2006-03-04 14:45
i want to count the number of paragraphs in my message of an article ,
but it gives the wrong number

example of paragraph :
<p><div class='paragraaf'><p><h4>Dick Advocaat verdient veel geld bij
Zuid-Korea</h4><div class='bericht'>De Zuid-Koreaanse voetbalbond legt
de Nederlandse bondscoach Dick Avocaat rijkelijk in de watten. De lokale
media melden dat Advocaat per jaar 605.000 euro opstrijkt. Zijn loon zou
een half miljoen euro bedragen. De verblijfskosten bedragen 75.000 euro
en het tekengeld 25.000. Advocaat krijgt ook een kleine
onkostenvergoeding om de hongerige maag te stillen.</div></p></div></p>

number = self.message.count("<p>")

it gives 27 as result but is has to 2 , what's my problem?

greetz

Klaas
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 unknown (Guest)
on 2006-03-04 15:10
(Received via mailing list)
Hi --

On Sat, 4 Mar 2006, klaas wrote:

> onkostenvergoeding om de hongerige maag te stillen.</div></p></div></p>
>
> number = self.message.count("<p>")
>
> it gives 27 as result but is has to 2 , what's my problem?

It's counting the total number of '>', 'p', and '<' characters.  Try
this:

   number = message.scan("<p>").size


David

--
David A. Black (dblack@wobblini.net)
Ruby Power and Light (http://www.rubypowerandlight.com)

"Ruby for Rails" chapters now available
from Manning Early Access Program! http://www.manning.com/books/black
7007cea0aa8f62646493ac4b50ae0641?d=identicon&s=25 klaas (Guest)
on 2006-03-04 15:52
thank you for your solution

klaas
This topic is locked and can not be replied to.