Private Function MidStr(ByVal Str As String, ByVal sStart As String, ByVal sEnd As String, Optional ByVal Start As Integer = 30) As String
Try
Dim iStart As Integer = Str.IndexOf(sStart, Start) + sStart.Length.ToString
Dim iEnd As Integer = Str.IndexOf(sEnd, iStart)
Return Str.Substring(iStart, iEnd - iStart)
Catch ex As Exception
Return String.Empty
End Try
End Function
beh du coup c'est le premier snippet mais que tu utilises mal
(et en plus il est pas bon, je le modifie)
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim mon_string As String = "blabla TOUTE LA SOURCE HTML lien FIN"
Dim sLink As String
Dim iLastPosition As Integer = 0
Do
iLastPosition = mon_string.IndexOf("http://", iLastPosition + 1)
sLink = MidStr(mon_string, "http://", ">", iLastPosition)
If sLink.Contains(" ") Then
mon_string = mon_string.Replace(sLink, sLink.Replace(" "c, "_"c))
End If
Loop While sLink.Contains(" ")
MessageBox.Show(mon_string)
End Sub
Private Function MidStr(ByVal Expression As String, ByVal sLeft As String, ByVal sRight As String, Optional ByVal iStart As Integer = -1) As String
Dim iPosL As Integer = Expression.IndexOf(sLeft, iStart)
If iPosL > -1 Then
Dim iPosR As Integer = Expression.IndexOf(sRight, iPosL + sLeft.Length)
If iPosR = -1 Then
'pas le caractère de fin, on prend la chaîne complète
iPosR = Expression.Length - iPosL - sLeft.Length
sRight = String.Empty
End If
Return Expression.Substring(iPosL, iPosR - iPosL)
End If
Return String.Empty
End Function
Je charge des mails d'une boite IMAP que j'enregistre au format .html en unicode ( System.Text.Encoding.Unicode) car sinon j'ai plein de caractères bizarre !
Mais le problème est que tous les liens http:// sont modifiés. Le caractère "_" est remplacé par un espace. Je cherche donc à remplacer tous les espaces de chacun de lien du mail par un "_".
Ouf!!!!
Vous n’avez pas trouvé la réponse que vous recherchez ?
J'ai un message d'erreur "L'index était hors limite. Il ne doit pas être négatif et doit être inférieur à la taille de la collection.
Nom du paramètre : StartIndex"