Découper une chaine [newbie]

Découper une chaine [newbie] - C#/.NET managed - Programmation

Marsh Posté le 28-02-2009 à 23:43:43    

Bonjour à tous,
 
je débute tout juste en c#
 
je souhaite pouvoir séparer une chaine avec un séparateur que je connais.
 
ex :  
 
string  : toto VS titi
string  : Titi, roger ET toto
 
j'aimerais pouvoir isoler le premier mot ou les premiers mots, qui se trouve avant VS ou ET.
 
merci d'avance de votre aide.

Reply

Marsh Posté le 28-02-2009 à 23:43:43   

Reply

Marsh Posté le 28-02-2009 à 23:58:33    

http://lmgtfy.com/?q=C%23+string+split&l=1


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 01-03-2009 à 14:40:07    

je n'y arrive pas ! j'arrive a splitter la chaine si elle contient un caractere comme , ou | mais pas a splitter sur du texte comme ma demande (VS ou ET)
 
merci

Reply

Marsh Posté le 01-03-2009 à 16:48:38    

a mon avis tu ferait mieux d'implémenter ton petit split perso!
 
Tu peux utiliser la fonction indexof avec tes séparateurs et prendre chaque fois la valeur la plus petite

Message cité 2 fois
Message édité par the big ben le 01-03-2009 à 16:49:44
Reply

Marsh Posté le 01-03-2009 à 16:50:03    

the big ben a écrit :

a mon avis tu ferait mieux d'implémenter ton petit split perso!
 
Tu peux utiliser la fonction indexof avec tes séparateurs et prendre chaque fois la valeur la plus petite


N'importe quoi [:prozac]


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 02-03-2009 à 16:19:25    

the big ben a écrit :

a mon avis tu ferait mieux d'implémenter ton petit split perso!

 

Tu peux utiliser la fonction indexof avec tes séparateurs et prendre chaque fois la valeur la plus petite


[:the real moins moins]

 

ouais ouais, ok lol ! et Regex.Split(), c'est fait pour les chiens ?

 
Code :
  1. string test = "titi roger ET toto";
  2. string[] words = Regex.Split(test, "ET" ); // words[0] contient la chaine située avant le "ET" et words[1] contient ce qui est situé après
  3. string[] singleWords = words[0].Split(new char[]{' '}); // on extrait chaque mot de words[0] via le séparateur espace
 

et ça va pas plus loin.

Message cité 1 fois
Message édité par Harkonnen le 02-03-2009 à 16:35:02

---------------
J'ai un string dans l'array (Paris Hilton)
Reply

Marsh Posté le 02-03-2009 à 16:35:17    

Harkonnen a écrit :


Code :
  1. string[] words = Regex.Split(test, "ET" ); // words[0] contient la chaine située avant le "ET" et words[1] contient ce qui est situé après



HarkoG [:sadnoir]

Code :
  1. string[] words = test.Split(new string[] {"ET"}, StringSplitOptions.None);


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 02-03-2009 à 16:39:12    

oui, aussi :D


---------------
J'ai un string dans l'array (Paris Hilton)
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed