I've automated most of my job functions with AHK over the last couple years. I've been meaning to tackle this problem for quite some time, but I finally got down to actually doing it today.
We have a ticketing system that I pull time-stamped notes from for different orders. The problem I have is that the notes that I scrape from the system are in all caps. I've searched the forums and haven't found anyone who's successfully created a sentence case script, so I decided to write it myself.
The script has two main functions; To split a string by common sentence-ending punctuation and make only the first character capitalized, and to make specific words either Title case or UPPER case.
For the latter, I'm using an INI file to save the lists of words that should be either title or upper case. For the former, I'm splitting the entire string by A_Space, checking to see if it should be upper or title case, and combining all the words from each sentence into seperate sentence variables, which are then combined back into the full string.
The GUI pulls the case lists from the INI file and provides a edit field to enter the text you want to alter.
The two subroutines (AddTC and AddUC) take whatever is in the clipboard, remove the spaces and punctuation, and add them to the appropriate case lists in the INI file.
The AlterCase subroutine reads the case lists, and alters the text.
Feel free to modify and redistribute.
Code:
#SingleInstance, Force
IniRead, TCList, SystemData.ini, CaseLists, TCList, ERROR
IniRead, UCList, SystemData.ini, CaseLists, UCList, ERROR
Gui, Add, GroupBox, x6 y7 w600 h150 , String
Gui, Add, Edit, x16 y27 w580 h120 vString,
Gui, Add, Button, x506 y167 w100 h30 gAlterCase, Alter Case
Gui, Add, Button, x6 y167 w100 h30 gAddTC, Add to Title Case
Gui, Add, Button, x116 y167 w110 h30 gAddUC, Add to Upper Case
Gui, Show, h209 w619, Sentence Case Testing GUI
Return
GuiClose:
ExitApp
AddTC:
IniRead, TCList, SystemData.ini, CaseLists, TCList, ERROR
clipboard = %clipboard%
clipboard := RegExReplace(clipboard, "[\.,\?!""]")
TCList := TCList . "," . clipboard
IniWrite, %TCList%, SystemData.ini, CaseLists, TCList
GoSub, AlterCase
Return
AddUC:
IniRead, UCList, SystemData.ini, CaseLists, UCList, ERROR
clipboard = %clipboard%
clipboard := RegExReplace(clipboard, "[\.,\?!""]")
UCList := UCList . "," . clipboard
IniWrite, %UCList%, SystemData.ini, CaseLists, UCList
GoSub, AlterCase
Return
AlterCase:
IniRead, TCList, SystemData.ini, CaseLists, TCList, ERROR
IniRead, UCList, SystemData.ini, CaseLists, UCList, ERROR
GuiControlGet, String
NewText=
DelimiterList := ".,?,!"
StringSplit, TextArray, String, %A_Space%
LineCount := 1
Loop, %TextArray0%
{
CurrentVar := TextArray%A_Index%
CurrentVar = %CurrentVar%
StringLower, CurrentVar, CurrentVar
TestVar := RegExReplace(CurrentVar, "[\.,\?!""]")
If TestVar in %UCList%
StringUpper, CurrentVar, CurrentVar
If TestVar in %TCList%
StringUpper, CurrentVar, CurrentVar, T
Sentence%LineCount% := Sentence%LineCount% . " " . CurrentVar
If Currentvar contains %DelimiterList%
{
CurrentSentence := Sentence%LineCount%
Sentence%LineCount% :=
CurrentSentence = %CurrentSentence%
StringLeft, CurrentSentenceFirstChar, CurrentSentence, 1
StringTrimLeft, CurrentSentenceRestChars, CurrentSentence, 1
StringUpper, CurrentSentenceFirstChar, CurrentSentenceFirstChar
CurrentSentence := CurrentSentenceFirstChar . CurrentSentenceRestChars
NewText = %NewText% %CurrentSentence%
LineCount += 1
}
}
Loop, %LineCount%
Sentence%LineCount% := ""
Loop, %TextArray0%
TextArray%A_Index% := ""
GuiControl,, String, %NewText%
Return