Classe String
| Description | Cette Classe permet de manipuler les chaînes de caractères (retourner,
ajouter une sous chaîne, remplacer une sous chaîne....) |
| Utilise | |
| API |
Option Compare Binary
Option Explicit
Private clsValue As String
Public Property Let Value(V As String)
clsValue = V
End Property
Public Property Get Value() As String
Value = clsValue
End Property
Public Function sLen() As Long
sLen = Len(clsValue)
End Function
Public Function Create(Optional strValue As String = "") As Boolean
Value = strValue
Create = True
End Function
Public Function Destroy() As Boolean
Destroy = True
End Function
Public Function subStr(lngStart As Long, Optional lngLen As Variant)
subStr = Mid(clsValue, lngStart, lngLen)
End Function
Public Function index(strSubString, Optional vntStart As Variant = 1) As Long
index = InStr(CInt(vntStart), clsValue, strSubString)
End Function
Public Function Left(lngLen As Long) As String
Left = VBA.Left(clsValue, lngLen)
End Function
Public Function Right(lngLen As Long) As String
If lngLen > 0 Then
Right = VBA.Right(clsValue, lngLen)
End If
End Function
Public Function Trim() As String
Trim = VBA.Trim(clsValue)
End Function
Public Function Substitue(ByVal strOrg As String, ByVal strRemp As Variant) As Variant
Dim i, j As Integer
Dim intLngRemp, intLngOrg As Integer
Dim s As New clsString
If IsNull(clsValue) Then
Exit Function
End If
s.Value = clsValue
If strOrg <> strRemp Then
With s
intLngRemp = Len(strRemp)
If intLngRemp = 0 Then
intLngRemp = 1
End If
intLngOrg = Len(strOrg)
i = 1
j = .index(strOrg, i)
While j <> 0
.Value = .Left(j - 1) & strRemp & .Right(.sLen - (j + intLngOrg - 1))
' i = j + intLngRemp
j = .index(strOrg)
Wend
End With
End If
Substitue = s.Value
Set s = Nothing
End Function
Public Function Reverse(Optional Start As Variant = 0, Optional Finish As Variant) As String
'Purpose : Inverse a string or part of a string
'Inputs : vntValue Value to process
' : Start Start position excluded (optional)
' : Finish End position included (optional)
'Assumes :
'Returns :
'Effects :
Dim i As Long
Dim r As Variant
Dim reste As Variant
Dim s As String
r = subStr(1, Start)
If IsMissing(Finish) Then
Finish = sLen
reste = ""
Else
reste = subStr(Finish + 1)
End If
i = Finish
While i > Start
r = r & subStr(i, 1)
i = i - 1
Wend
s = r & reste
Reverse = s
End Function
Public Function Add(s As String)
clsValue = clsValue & s
End Function
Public Function Remove(s As String)
clsValue = Substitue(s, "")
End Function