caco64
Messages postés69Date d'inscriptionjeudi 27 septembre 2007StatutMembreDernière intervention14 décembre 2007 9 oct. 2007 à 19:50
Le pb c'est que ne suis pas tout à fait sûr d'avoir compris ce que tu veux faire.
voilà ce que je te propose :
phrase = "05919 frtg 0753786378 368687578678 yuim 786786766"
a = "frtg"
b = "yuim"
If InStr(phrase, b) > 0 Then
ca = InStr(phrase, a)
cb = InStr(phrase, b)
ch1 = Mid(phrase, ca, (cb - ca))
ch1 = ch1 & b
MsgBox ch1
'If ch1 <> "" Then List2.AddItem ch1 & b
caco64
Messages postés69Date d'inscriptionjeudi 27 septembre 2007StatutMembreDernière intervention14 décembre 2007 9 oct. 2007 à 20:44
Ok, essaie ça :
Sub test1()
Dim ch() As String
phrase = "05919 AxxxxxxB AyyyyyyyyyB AzzzzzzzzzB gfhgj"
a = "A"
b = "B"
long_phrase = Len(phrase)
long_a = Len(a)
long_b = Len(b)
i = 0
ca = 0
cb = 0
Do Until InStr((cb + 1), phrase, a) = 0
i = i + 1
ReDim Preserve ch(1 To i)
ca = InStr((cb + 1), phrase, a)
cb = InStr(ca, phrase, b) + long_b
ch(i) = Mid(phrase, ca, (cb - ca))
Loop
i_fin = i
msg = "Il y a " & i_fin & " mots, les voici :" & Chr(10)
For i = 1 To i_fin
msg = msg & "mot" & i & " : " & ch(i) & Chr(10)
Next i
MsgBox msg
End Sub
jmfmarques
Messages postés7666Date d'inscriptionsamedi 5 novembre 2005StatutMembreDernière intervention22 août 201427 10 oct. 2007 à 08:54
Pour plusieurs raisons...
Dont la principale est que tu détermines ton p2 par rapport à str et que tu utilises cette position dans ... une chaîne différente !!!
Au fait : change donc de nom pour ta chaine (Str est un mot réservé de Vb).