Petit coup de patte en VB.net

Résolu
cs_clinik Messages postés 34 Date d'inscription vendredi 12 novembre 2004 Statut Membre Dernière intervention 1 novembre 2012 - 1 nov. 2012 à 15:16
cs_clinik Messages postés 34 Date d'inscription vendredi 12 novembre 2004 Statut Membre Dernière intervention 1 novembre 2012 - 1 nov. 2012 à 15:44
Allo à tous,

J'ai une function qui sert a donner ce qui est entre 2 caractères.
Ce que je cherche a faire c'est d'augmenter la limite de caractère puisque pour l'instant on ne peut qu'en definir 1

Private Function Entre(ByVal txt, ByVal Car1, ByVal Car2) As String
        Entre = Mid(txt, InStr(1, txt, Car1) + 1, InStr(InStr(1, txt, Car1) + 1, txt, Car2) - InStr(1, txt, Car1) - 1)
    End Function

2 réponses

Utilisateur anonyme
1 nov. 2012 à 15:37
Bonjour

On dirais tu VB6, tu devrai décocher l'import Microsoft.VisualBasic dans les options de ton projet (attention tu aura surement pleins d'erreurs à corriger)
Ajoute aussi un Option Strict On au début de chacun fichier vb.
Utilise plutôt les méthodes de la class String


Donc, si j'ai bien compris ta demande :

Private Function Entre(ByVal txt As String, ByVal Car1 As String, ByVal Car2 As String) As String
  Dim iStart, iEnd, length As Integer
  iStart = txt.IndexOf(Car1) + Car1.Length
  If iStart > -1 Then
    iEnd = txt.IndexOf(Car2, iStart)
    If iEnd > -1 Then
      length = iEnd - iStart
    End If
  End If
  If length > 0 Then
    Return txt.Substring(iStart, length)
  Else
    Return String.Empty
  End If
End Function



_____________
Kenji
3
cs_clinik Messages postés 34 Date d'inscription vendredi 12 novembre 2004 Statut Membre Dernière intervention 1 novembre 2012
1 nov. 2012 à 15:44
Merci pour cette réponse aussi tôt et fonctionnel :)

De ma part, cela fonctionnait sauf que cela fonctionnais seulement pour le car2



merci beaucoup
0
Rejoignez-nous