PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Split
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Split

Réponse
 
LinkBack Outils de la discussion
Vieux 17/09/2007, 01h03   #1
Lee Jarvis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Split

Ok guys im looking for something sexy to split this HTML (This HAS to be
done using split, nothing else)

<b>hi</b>, <b>there</b>, <b>fred</b>,

I would like to split them values into an array, Is there any chance
this can be done? Because im beginning to think there isn't

Tia
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 17/09/2007, 01h04   #2
Lee Jarvis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Split

Oh, i want all the values inside the <b></b> tags, btw

--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 17/09/2007, 01h44   #3
Gregory Seidman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Split

On Mon, Sep 17, 2007 at 09:03:52AM +0900, Lee Jarvis wrote:
> Ok guys im looking for something sexy to split this HTML (This HAS to be
> done using split, nothing else)
>
> <b>hi</b>, <b>there</b>, <b>fred</b>,
>
> I would like to split them values into an array, Is there any chance
> this can be done? Because im beginning to think there isn't
>
> Oh, i want all the values inside the <b></b> tags, btw


str.split(/<b>|<\/b>,|<\/b>, <b>/)

> Tia

--Greg


  Réponse avec citation
Vieux 17/09/2007, 02h00   #4
Phlip
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Split

Gregory Seidman wrote:

>> Oh, i want all the values inside the <b></b> tags, btw

>
> str.split(/<b>|<\/b>,|<\/b>, <b>/)


I thought, among other attrocities, that < was a reserved character for
regular expressions.

Not sure about the "has to be done using .split part", if some of us have
studied REXML and Hpricot so thoroughly... (-;

--
Phlip
http://www.oreilly.com/catalog/9780596510657/
"Test Driven Ajax (on Rails)"
assert_xpath, assert_javascript, & assert_ajax


  Réponse avec citation
Vieux 17/09/2007, 02h10   #5
William James
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Split

On Sep 16, 7:03 pm, Lee Jarvis <jarv...@gmail.com> wrote:
> Ok guys im looking for something sexy to split this HTML (This HAS to be
> done using split, nothing else)
>
> <b>hi</b>, <b>there</b>, <b>fred</b>,
>
> I would like to split them values into an array, Is there any chance
> this can be done? Because im beginning to think there isn't



"<b>hi</b>, <b>there</b>, <b>fred</b>,".scan(/<b>(.*?)<.b>/).
flatten
==>["hi", "there", "fred"]

"<b>hi</b>, <b>there</b>, <b>fred</b>,".
split(%r{<b>|</b>[, ]*(?:<b>)?})
==>["", "hi", "there", "fred"]

  Réponse avec citation
Vieux 17/09/2007, 09h23   #6
Arindam Goswami
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Split

Lee Jarvis wrote:
> Ok guys im looking for something sexy to split this HTML (This HAS to be
> done using split, nothing else)
>
> <b>hi</b>, <b>there</b>, <b>fred</b>,
>
> I would like to split them values into an array, Is there any chance
> this can be done? Because im beginning to think there isn't
>
> Tia



There you go ---
f.split(/, |,/)

where f is your string.
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 17/09/2007, 09h35   #7
Lee Jarvis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Split

Arindam Goswami wrote:
> Lee Jarvis wrote:
>> Ok guys im looking for something sexy to split this HTML (This HAS to be
>> done using split, nothing else)
>>
>> <b>hi</b>, <b>there</b>, <b>fred</b>,
>>
>> I would like to split them values into an array, Is there any chance
>> this can be done? Because im beginning to think there isn't
>>
>> Tia

>
>
> There you go ---
> f.split(/, |,/)
>
> where f is your string.



Thanks, but i need to values inside the <b> tags, So <b>hello</b> I need
hello..
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 17/09/2007, 09h47   #8
William James
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Split

On Sep 16, 7:03 pm, Lee Jarvis <jarv...@gmail.com> wrote:
> Ok guys im looking for something sexy to split this HTML (This HAS to be
> done using split, nothing else)


Why won't your teacher let you use anything
other than split?

Does he know that you are getting your answers
from this forum?

  Réponse avec citation
Vieux 17/09/2007, 10h15   #9
Arindam Goswami
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Split

Lee Jarvis wrote:

> Thanks, but i need to values inside the <b> tags, So <b>hello</b> I need
> hello..


Quick and dirty, but it works --

f.split(/, |,/).to_s.split(/<b>/).to_s.split(/<\/b>/)

could not figure out how to do this in one split
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 17/09/2007, 10h36   #10
Arindam Goswami
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Split

This one is better--

f.split(/<\/b>, <b>|<\/*b>,*/)

but it leaves you with one blank cell
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 17/09/2007, 14h13   #11
Lee Jarvis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Split

William James wrote:
> On Sep 16, 7:03 pm, Lee Jarvis <jarv...@gmail.com> wrote:
>> Ok guys im looking for something sexy to split this HTML (This HAS to be
>> done using split, nothing else)

>
> Why won't your teacher let you use anything
> other than split?
>
> Does he know that you are getting your answers
> from this forum?


Who said it was a teacher, This was for a challenge, And you're not
providing an answers, Just a very ful solution..

Thank you all
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 20h57.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15300 seconds with 19 queries