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 > Get value from string
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Get value from string

Réponse
 
LinkBack Outils de la discussion
Vieux 24/02/2008, 19h11   #1
Luca Roma
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Get value from string

I have a string that content a link of a youtube page .
Like:
http://it.youtube.com/watch?v=PupR5V9aE2s&test=1

i want get the value of v:
PupR5V9aE2s

How i can do?
Thanks
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 24/02/2008, 19h17   #2
Stefano Crocco
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Get value from string

Alle Sunday 24 February 2008, Luca Roma ha scritto:
> I have a string that content a link of a youtube page .
> Like:
> http://it.youtube.com/watch?v=PupR5V9aE2s&test=1
>
> i want get the value of v:
> PupR5V9aE2s
>
> How i can do?
> Thanks


If you know that the part of the string you want is delimited by v= and &, you
can use this:

str.match(/v=([^&]*)/)[1]

Stefano




  Réponse avec citation
Vieux 24/02/2008, 19h22   #3
Luca Roma
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Get value from string

Thanks stefano for the responce

There are 2 possible links:
http://it.youtube.com/watch?v=PupR5V9aE2s&test=1
http://it.youtube.com/watch?v=PupR5V9aE2s


str.match(/v=([^&]*)/)[1]
Is your command valid also for the second link?
Thanks

Stefano Crocco wrote:
> Alle Sunday 24 February 2008, Luca Roma ha scritto:
>> I have a string that content a link of a youtube page .
>> Like:
>> http://it.youtube.com/watch?v=PupR5V9aE2s&test=1
>>
>> i want get the value of v:
>> PupR5V9aE2s
>>
>> How i can do?
>> Thanks

>
> If you know that the part of the string you want is delimited by v= and
> &, you
> can use this:
>
> str.match(/v=([^&]*)/)[1]
>
> Stefano


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

  Réponse avec citation
Vieux 24/02/2008, 19h41   #4
Stefano Crocco
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Get value from string

Alle Sunday 24 February 2008, Luca Roma ha scritto:
> Thanks stefano for the responce
>
> There are 2 possible links:
> http://it.youtube.com/watch?v=PupR5V9aE2s&test=1
> http://it.youtube.com/watch?v=PupR5V9aE2s
>
>
> str.match(/v=([^&]*)/)[1]
> Is your command valid also for the second link?
> Thanks
>
> Stefano Crocco wrote:
> > Alle Sunday 24 February 2008, Luca Roma ha scritto:
> >> I have a string that content a link of a youtube page .
> >> Like:
> >> http://it.youtube.com/watch?v=PupR5V9aE2s&test=1
> >>
> >> i want get the value of v:
> >> PupR5V9aE2s
> >>
> >> How i can do?
> >> Thanks

> >
> > If you know that the part of the string you want is delimited by v= and
> > &, you
> > can use this:
> >
> > str.match(/v=([^&]*)/)[1]
> >
> > Stefano


Yes. The regexp I used looks for the string v= followed by any number of
characters which are not '&'. Those characters are put into the first group of
the returned MatchData. Since your second link doesn't contain the '&', the
match will go on until the end, which should give you what you want.

Stefano


  Réponse avec citation
Vieux 24/02/2008, 20h30   #5
Thomas Preymesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Get value from string

[Note: parts of this message were removed to make it a legal post.]

On 24/02/2008, Luca Roma <roma@nerto.it> wrote:
>
> I have a string that content a link of a youtube page .
> Like:
> http://it.youtube.com/watch?v=PupR5V9aE2s&test=1




irb(main):001:0> require 'uri'
=> true
irb(main):002:0> res = URI.split('
http://it.youtube.com/watch?v=PupR5V9aE2s&test=1')
=> ["http", nil, "it.youtube.com", nil, nil, "/watch", nil,
"v=PupR5V9aE2s&test=1", nil]

gives you an array of:

* Scheme
* Userinfo
* Host
* Port
* Registry
* Path
* Opaque
* Query
* Fragment

-Thomas

  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 13h46.


Édité par : vBulletin®
Copyright ©2000 - 2009, 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,57580 seconds with 13 queries