iCode Posted March 28, 2015 Posted March 28, 2015 (edited) This is a spin-off of >Seeker's function which i rewrote and tried to optimize for doing only sentence casing and for better Unicode handling. Haven't done a lot of testing with it, but it seems to work well so far. #include-once ; #FUNCTION# ==================================================================================================================== ; Name ..........: _SentenceCase ; Description ...: Capitalize the first letter of sentences. ; Syntax ........: _SentenceCase(Byref $sString) ; Parameters ....: $sString: [in/out] A string value. ; Return values .: Success: A string is returned. ; Failure: Sets @error = 1 and returns 0. ; Author ........: iCode ; Modified ......: 30-MAR-2015 ; Remarks .......: ; Related .......: http://www.autoitscript.com/forum/topic/147086-udf-for-title-case-initial-caps-and-sentence-case/ ; Link ..........: http://www.autoitscript.com/forum/topic/169290-sentence-case-capitalize-first-letter-of-sentences/ ; Example .......: No ; =============================================================================================================================== Func _SentenceCase(ByRef $sString) Local $aStr = StringRegExp($sString, "(*UCP)(?s)[[:alpha:]].+?(?:[.?!:;]|\z)\s*|[^[:alpha:]]+", 3) If @error Then Return SetError(1, 0, 0) Local $sChar, $sRet = "" For $i = 0 To UBound($aStr) - 1 If StringRegExp($aStr[$i], "(*UCP)(?s)^[[:alpha:]]+.*?[.?!:;]") Then $sChar = StringLeft($aStr[$i], 1) If StringIsLower($sChar) Then $aStr[$i] = StringUpper($sChar) & StringTrimLeft($aStr[$i], 1) EndIf EndIf $sRet &= $aStr[$i] Next Return $sRet EndFuncCHANGE LOG: 28-MAR-2015 - initial version 30-MAR-2015 - added more sentence terminition characters ( ; : ) - should probably get these from a variable? Edited March 30, 2015 by iCode FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences) CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)
Malkey Posted March 29, 2015 Posted March 29, 2015 I found for these sentences, "wait a minute! where are the capitalize first letters?", to work, If StringRegExp($aStr[$i], "(*UCP)(?s)^[[:alpha:]]+.*?\.") Then has to be changed to this, If StringRegExp($aStr[$i], "(*UCP)(?s)^[[:alpha:]]+.*?[?!.]") Then
iCode Posted March 29, 2015 Author Posted March 29, 2015 whoops! yes, that was obvious. thanks first post updated. FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences) CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now