1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| Option Explicit
dim tmp
Function myMid(S, Start, Lng)
' S = Chaine dans laquelle se fait la recherche
' Start = Position à partir de laquelle on commence la copie
' Lng = Longueur de la sous-chaine à obtenir
Dim i, n, Lg, Ch, sLeft, sRight
n = Len(S)
If Start < 1 Or Start > n Or (Start+Lng-1 > n) Or (Lng > n) then Ch = "" ' On est en dehors de la chaine ?!
If Start >= 1 And Start <= n Then
Lg = Start + Lng - 1
Ch = ""
For i = Start To Lg
sLeft = Left(S, i) ' On récupère une chaine de longueur Start à partir de la gauche
sRight = Right(sLeft,1) ' On récupère le dernier caractère de la chaine précédente
Ch = Ch + sRight ' on fait la concaténation de la chaine Ch avec le caractère obtenu
Next
End If
myMid = Ch
End Function
tmp = myMid("Trois jours durant, j'ai cherché la solution mais en vain", 7, 5)
MsgBox tmp |