La première _sStrFrAccentRemove permet de supprimer les accents dans une chaîne de caractères en se basant sur les caractères accentués du français en respectant la "case" des lettres.
Code : Tout sélectionner
#include <String.au3>
#include <StringConstants.au3>
Func _sStrFrAccentRemove($sString)
;&========================================================================================================================
;& Description....: Convert characters with accent to a fom without accent based on french language
;& Parameter(s)...:
;& $sString to convert
;& Return value(s)
;& Function..: String converted
;& Error(s)..: -
;& -
;& Versions.......: 1.0.0
;& -
;& Author(s)......: Jean-Pol Dekimpe (Jeep)
;& Date...........: 2019/01/01
;& Language.......: English
;& AutoIt.........: v3.3.14.5
;& -
;& Remark(s)......: Conversion is based on french language
;&========================================================================================================================
Local $sFrom = "àáâãäåæçèéêëìíîïòóôöùúûüýÿœ", $sChar = "", $sOutString = ""
Local $aTo = ["a", "a", "a", "a", "a", "a", "ae", "c", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", _
"u", "u", "u", "u", "y", "y", "oe"]
Local $aChars = StringSplit($sString, "")
Local $iPos = 0
For $i = 1 To $aChars[0]
$sChar = $aChars[$i]
$iPos = StringInStr($sFrom, $sChar)
If $iPos = 0 Then
$sOutString &= $sChar
Else
If StringIsUpper($sChar) Then
$sOutString &= StringUpper($aTo[$iPos])
Else
$sOutString &= $aTo[$iPos]
EndIf
EndIf
Next
Return $sOutString
EndFunc ;==>_sStrFrAccentRemove
Code : Tout sélectionner
Func _sStrTitleCase($sString, $sLanguage = "FR")
;&========================================================================================================================
;& Description....: Uppercase first letter of each word + support a French context
;& No uppercase after "'"
;& Parameter(s)...:
;& $sString - string of characters to convert
;& $sLanguage = "FR" like French to process accent characters; They are removed before converting to
;& uppercase
;& Return value(s)
;& Function..: resulting string
;& Error(s)..: -
;& -
;& Versions.......: 1.0.0
;& -
;& Author(s)......: Jean-Pol Dekimpe (Jeep)
;& Date...........: 2019/01/01
;& Language.......: English
;& AutoIt.........: v3.3.14.5
;& -
;& Remarks........: -
;&========================================================================================================================
Local $bCapNext = True
Local $sChr = "", $sReturn = ""
Local $aChars = StringSplit($sString, "")
For $i = 1 To $aChars[0]
$sChr = $aChars[$i]
Select
Case $bCapNext = True
If StringRegExp($sChr, "[a-zA-Z\xC0-\xFF0-9]") Then
If $sLanguage = "FR" Then $sChr = (_sStrFrAccentRemove($sChr))
$sChr = StringUpper($sChr)
$bCapNext = False
EndIf
s. Case ($sLanguage <> "FR" And Not StringRegExp($sChr, "[a-zA-Z\xC0-\xFF'0-9]")) Or _
(Not StringRegExp($sChr, "(*UCP)[a-zA-Z\xC0-\xFF0-9'’]"))
$bCapNext = True
Case Else
$sChr = StringLower($sChr)
EndSelect
$sReturn &= $sChr
Next
Return $sReturn
EndFunc ;==>_sStrTitleCase
Code : Tout sélectionner
#include <String.au3>
#include <StringConstants.au3>
_sStrFrAccentRemove_eval();
_sStrTitleCase_eval()
Exit
Func _sStrFrAccentRemove_eval()
Local $sText = "l'élève de première année va à la piscine"
_CW($sText)
$sText = _sStrFrAccentRemove($sText)
_CW($sText)
EndFunc
Func _sStrTitleCase_eval()
;_sStrTitleCase($sString, $sLanguage = "FR")
Local $sText = "l'élève de première année va à la piscine"
_CW(_sStrTitleCase($sText))
Local $sText = "I can't get now, satisfaction ..."
_CW(_sStrTitleCase($sText))
EndFunc
;-----------------------------------------------------------------------------------------------------------------------------
Func _CW($sText, $sBOL = "Trace >", $sEOL = "<", $bNewLine = True)
;&=======================================================================================================================
;& Description....: Write a message on console with a specified begin and end of Line
;& Parameter(s)...:
;& $sText - Text to write
;& $sBOL - Begin of line
;& $sEOL - End of Line
;& $bNewLine : put a new line after writing the message
;& Return value(s)
;& Function..: -
;& Error(s)..: -
;& -
;& Versions.......: 1.1.0
;& -
;& Author(s)......: Jean-Pol Dekimpe (Jeep)
;& Date...........: 2019/01/15
;& Modify ........: -
;& -
;& Remark(s)......: simplify use of ConsoleWrite
;========================================================================================================================
If $bNewLine Then $sEOL &= @CRLF
ConsoleWrite($sBOL & $sText & $sEOL)
EndFunc ;==>_CW
Func _sStrFrAccentRemove($sString)
;&========================================================================================================================
;& Description....: Convert characters with accent to a fom without accent based on french language
;& Parameter(s)...:
;& $sString to convert
;& Return value(s)
;& Function..: String converted
;& Error(s)..: -
;& -
;& Versions.......: 1.0.0
;& -
;& Author(s)......: Jean-Pol Dekimpe (Jeep)
;& Date...........: 2019/01/01
;& Modify ........: -
;& -
;& Remark(s)......: Conversion is based on french language
;&========================================================================================================================
Local $sFrom = "àáâãäåæçèéêëìíîïòóôöùúûüýÿœ", $sChar = "", $sOutString = ""
Local $aTo = ["a", "a", "a", "a", "a", "a", "ae", "c", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", _
"u", "u", "u", "u", "y", "y", "oe"]
Local $aChars = StringSplit($sString, "")
Local $iPos = 0
For $i = 1 To $aChars[0]
$sChar = $aChars[$i]
$iPos = StringInStr($sFrom, $sChar)
If $iPos = 0 Then
$sOutString &= $sChar
Else
If StringIsUpper($sChar) Then
$sOutString &= StringUpper($aTo[$iPos])
Else
$sOutString &= $aTo[$iPos]
EndIf
EndIf
Next
Return $sOutString
EndFunc ;==>_sStrFrAccentRemove
Func _sStrTitleCase($sString, $sLanguage = "FR")
;&========================================================================================================================
;& Description....: Uppercase first letter of each word + support a French context
;& No uppercase after "'"
;& Parameter(s)...:
;& $sString - string of characters to convert
;& $sLanguage = "FR" like French to process accent characters; They are removed before converting to
;& uppercase
;& Return value(s)
;& Function..: resulting string
;& Error(s)..: -
;& -
;& Versions.......: 1.0.0
;& -
;& Author(s)......: Jean-Pol Dekimpe (Jeep)
;& Date...........: 2019/01/01
;& Language.......: English
;& AutoIt.........: v3.3.14.5
;& -
;& Remarks........: -
;&========================================================================================================================
Local $bCapNext = True
Local $sChr = "", $sReturn = ""
Local $aChars = StringSplit($sString, "")
For $i = 1 To $aChars[0]
$sChr = $aChars[$i]
Select
Case $bCapNext = True
If StringRegExp($sChr, "[a-zA-Z\xC0-\xFF0-9]") Then
If $sLanguage = "FR" Then $sChr = (_sStrFrAccentRemove($sChr))
$sChr = StringUpper($sChr)
$bCapNext = False
EndIf
Case ($sLanguage <> "FR" And Not StringRegExp($sChr, "[a-zA-Z\xC0-\xFF'0-9]")) Or _
(Not StringRegExp($sChr, "(*UCP)[a-zA-Z\xC0-\xFF0-9'’]"))
$bCapNext = True
Case Else
$sChr = StringLower($sChr)
EndSelect
$sReturn &= $sChr
Next
Return $sReturn
EndFunc ;==>_sStrTitleCase