[FUNC] Convertit une chaine AZERTY <=> QWERTY
Posté : sam. 13 févr. 2010 14:10
Pour les besoins d'une question du forum, voici une fonction qui permet de convertir une chaine AZERTY en Chaine QWERTY et vice versa.
Le code pourrait être très certainement diminuer en évitant de répéter le code de conversion, mais je trouve que c'est très clair en l'état, et de toutes façons, on est pas à 10 lignes prêt ...
En l'état, seul les lettres sont prises en compte, donc si quelqu'un à le temps de faire la table de conversion, je mettrais à jour le code.
Exemple d'utilisation :
Le code pourrait être très certainement diminuer en évitant de répéter le code de conversion, mais je trouve que c'est très clair en l'état, et de toutes façons, on est pas à 10 lignes prêt ...

En l'état, seul les lettres sont prises en compte, donc si quelqu'un à le temps de faire la table de conversion, je mettrais à jour le code.

Code : Tout sélectionner
Func _KeybConvert($sString, $Type = 1) ; 1 = AZERTY To QWERTY 2 = QWERTY To AZERTY
If $sString = '' Then
SetError(1)
Return ''
EndIf
If $Type <> 1 And $Type <> 2 Then
SetError(1)
Return ''
EndIf
Local $Azerty = "aAmMqQwWzZ;:,.!/?%*$&'-@+=<>[]{}"
Local $Qwerty = "qQ,?aAzZwWmM;:!&§(_'èù)é+=./^$¨£"
Local $Char, $Res, $j, $i
Local $aAzerty = StringSplit($Azerty, "")
Local $aQwerty = StringSplit($Qwerty, "")
Switch $Type
Case 1 ; AZERTY To QWERTY
For $j = 1 To StringLen($sString)
$Char = StringMid($sString, $j, 1)
If StringInStr($Azerty, $Char, 1) Then
For $i = 1 To $aAzerty[0]
If $Char == $aAzerty[$i] Then
$Char = $aQwerty[$i]
ExitLoop
EndIf
Next
EndIf
$Res &= $Char
Next
Case 2 ; QWERTY To AZERTY
For $j = 1 To StringLen($sString)
$Char = StringMid($sString, $j, 1)
If StringInStr($Qwerty, $Char, 1) Then
For $i = 1 To $aQwerty[0]
If $Char == $aQwerty[$i] Then
$Char = $aAzerty[$i]
ExitLoop
EndIf
Next
EndIf
$Res &= $Char
Next
EndSwitch
Return $Res
EndFunc ;==>_KeybConvert
Code : Tout sélectionner
MsgBox(0, 'azerty => qwerty', _KeybConvert('azerty', 1))
MsgBox(0, 'qwerty => azerty', _KeybConvert('qwerty', 2))