alias666
Messages postés308Date d'inscriptionmardi 1 juin 2004StatutMembreDernière intervention23 mars 2010
-
9 avril 2008 à 11:48
alias666
Messages postés308Date d'inscriptionmardi 1 juin 2004StatutMembreDernière intervention23 mars 2010
-
9 avril 2008 à 14:01
Bonjour à tous !
J'ai un soucis avec une regexp, je dois trouver dans un champ le caractère "-" il n'y en a qu'un dans le champs, une fois que je trouve ce caractère, je dois stocker le caractère après ce "-".
Exemple : 15R41-1254
Je dois récupérer "1"
Je vous montre mon bout de code traitant du problème. Apparement $1 pour récupérer cela n'est pas bon. Sinon pour ce qui est de mon pattern le voici : Dim Regexp As New Regex("1.+\-(.).*$")
Merci.
<hr size="2" width="100%" />
While myreader.Read()
'Assignation des variables
DataBase = myreader.GetValue(1)
McuCode = myreader.GetValue(0) myCommand4 New System.Data.Odbc.OdbcCommand("SELECT McuName FROM " & DataBase & ".T_MCU where McuCode'" & McuCode & "'", connexion2)
myAdapter4 = New System.Data.Odbc.OdbcDataAdapter(myCommand4)
'Requete pour récupérer McuName
Dim myreader2 As System.Data.Odbc.OdbcDataReader = myCommand4.ExecuteReader(CommandBehavior.CloseConnection)
ReDim McuName(myreader2.RecordsAffected)
If myreader2.RecordsAffected > 0 Then
'Affichage des données
myreader2.Read()
Regexp.Match(myreader.GetValue(5))
If $1 = "1" then
datanumber(i) = "Tracteur"
End If
If $1 = "2" then
datanumber(i) = "Semi"
End If
If $1 = "3" then
datanumber(i) = "Porteur"
End If
<hr size="2" width="100%" />
_______________________
<<<< :-: 4L!@$ :-: >>>>
lesdis
Messages postés403Date d'inscriptionmercredi 19 avril 2006StatutMembreDernière intervention 7 août 2020 9 avril 2008 à 12:20
Bonjour,
Une solution afin de récupérer les valeurs d'une expression régulière :
Dim MyRegExp As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(name, "^1.+\-(.).*$ ")
Dim value As String = MyRegExp.Groups(1).Value
La variable name contient ton texte a analyser.
Dans le tableau Groups() tu retrouve tous ce qui correspond à ta regexp à l'index 0 puis les valeurs récupérées dans les parenthèse en commencant par celle la plus à gauche.