Sub GaucheDroite()
MsgBox Left("abcdef", 3)
MsgBox Right("abcdef", 2)
End Sub
Sub MilieuChaine()
MsgBox Mid("abcde", 3, 2) ' renvoie cd
MsgBox Mid("abcde", 3, 10) ' renvoie cde
MsgBox Mid("abcde", 10, 3) ' renvoie une chaîne nulle
End Sub
Sub FonctionInStr()
' Exemple 1 : X contiendra 2
MsgBox InStr("abc", "b")
' Exemple 2 : X contiendra 0
MsgBox InStr("abc", "B")
' Exemple 3 : X contiendra 2
MsgBox InStr("abc", "bc")
' Si dans la section General/Declarations, on écrit Option Compare Text,
on peut comparer avec succès les minuscules et les majuscules. Si par contre
on écrit Option
' Compare Binary (option par défaut), les caractères ASCII sont purement
comparés.
' Mais, on peut avoir Option Compare Binary, et malgré tout, exceptionnellement
demander une comparaison de texte avec :
MsgBox InStr(0, "abc", "B", 1)
End Sub
Sub FonctionChr()
MsgBox Chr("a") ' renvoie 97 (code ASCII de a)
End Sub
Sub LongueurChaine()
MsgBox Len("abc") ' renvoie 3 (lettres)
End Sub
Sub MajusculeMinuscule()
MsgBox UCase("textE") ' renvoie TEXTE
MsgBox UCase("téxte") ' renvoie TÉXTE
MsgBox LCase("TExte") ' renvoie texte
End Sub
Sub FonctionVal()
MsgBox Val(" 21x") ' renvoie 21
MsgBox Val("x21") ' renvoie 0
MsgBox Val(21) ' donne une erreur (le paramètre doitêtre une chaîne de
caractères)
End Sub