Quelques fonctions de manipulation de chaines de caractères

Les fonctions traitées sont: String, Split, Mid, InStr, Len, Left, Right, UCase, LCase et Trim


Code source:

Option Explicit

Sub test_split()
Dim chemin As String, a As Variant, e As Variant
chemin = ThisWorkbook.Path
Debug.Print chemin

Debug.Print String(100, "-")

a = Split(chemin, "\")
For Each e In a
    Debug.Print e
Next
End Sub


Sub test_split2()
Dim chemin As String
Dim i, ideb
chemin = ThisWorkbook.Path
Debug.Print chemin
Debug.Print String(100, "-")
i = 0
ideb = 0
Do
    i = InStr(i + 1, chemin, "\")
    Debug.Print Mid(chemin, ideb + 1, IIf(i = 0, Len(chemin), i - 1) - ideb)
    ideb = i
Loop Until i = 0
End Sub

Sub test_leftright()
Dim NC As String, nomfichier As String, ext As String

NC = ThisWorkbook.Name
nomfichier = Left(NC, InStr(NC, ".") - 1)
ext = Right(NC, Len(NC) - InStr(NC, "."))
Debug.Print "Nom complet:" & NC & " Fichier:" & nomfichier & " ,extension:" & ext

Dim a
a = Split(NC, ".")
Debug.Print "Nom complet:" & NC & " Fichier:" & a(0) & " ,extension:" & a(1)
End Sub

Sub test_majmin()
Dim s As String
s = "Bonjour tout le monde"

Debug.Print UCase(s)
Debug.Print LCase(s)

Debug.Print Format(s, ">")
Debug.Print Format(s, "<")
End Sub

Sub test_trim()
Dim s As String

s = " Bon jour" & Space(5)

Debug.Print s & " de longeur " & Len(s)
Debug.Print Trim(s) & " de longeur " & Len(Trim(s))
End Sub

Commentaires

Posts les plus consultés de ce blog

Nom des services Windows en Français et en Anglais

How to determine eigenvalues and eignevectors of a matrix in Excel

Analyse de Fourrier sur Excel