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
PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 201847 29 juil. 2009 à 18:02
... ok
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
dsigmoun
Messages postés135Date d'inscriptionjeudi 31 juillet 2008StatutMembreDernière intervention25 février 20232 29 juil. 2009 à 17:11
Je vais être précis dans action.
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 ?
dsigmoun
Messages postés135Date d'inscriptionjeudi 31 juillet 2008StatutMembreDernière intervention25 février 20232 30 juil. 2009 à 09:02
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"