Proper Capitalization of a Tile, Not Just Upper Case of All Words. Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
BannerStore
Posts: 31
Joined: 06 Sep 2017, 19:29

Proper Capitalization of a Tile, Not Just Upper Case of All Words.

13 Jan 2020, 13:48

Hello, Everyone! Love you guys.

Here is a script that I pieced together from threads here and there on this forum. This script converts sentences so all letters are changed to upper case, to lower case, to a properly formatted title case, and then back again by toggling control + shift + alt + U.

(I would also love to add First Case (the first letter of all words are capitalized), Pascal case (first letter capitalized with spaces removed), Snake case (words separated by hyphen for file naming purposes), and Dot case (dots in between all the words) but I don't want to be greedy!)

However, the title case section of my script capitalizes ALL the words. How can I modify it so that it only capitalizes important words? In other words, as long as it doesn't start the sentence, words like "the", "a", "of", etc. are not capitalized.

I've scoured the threads but no one seems to have put out a complete script that is a modification of the below script. (There is another script floating around that uses RegEx which I have no idea how to use so I'm hoping that I don't have to use that because I don't understand it. I tried to just run the RegEx script but I couldn't make it work. Neither could I fix it because I have no idea what the script is saying.)

Here is my script. Please tell me what I need to change:

Code: Select all

cycleNumber:= 1

^+!u::
If (cycleNumber==1)
{
	ConvertSentence()
	cycleNumber:= 2
}
Else If (cycleNumber==2)
{
	ConvertUpper()
	cycleNumber:= 3
}
Else
{
	ConvertLower()
	cycleNumber:= 1
}
Return

ConvertSentence()
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard
	SendInput, ^c ; Copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringUpper, Clipboard, Clipboard, T ;Convert case
	Clipboard := RegExReplace(Clipboard, "(((^|([.!?]+\s+))[a-z])| i | i')", "$u1")
	Len:= Strlen(Clipboard) ;Set number of characters
	Send %Clipboard% ;Send new string
	Send +{left %Len%} ;Re-select text
	VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave ;Restore previous clipboard
}

ConvertUpper()
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringUpper, Clipboard, Clipboard ;Convert case
	Len:= Strlen(Clipboard) ;Set number of characters
    	Send %Clipboard% ;Send new string
	Send +{left %Len%} ;Re-select text
    	VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave ;Restore previous clipboard
}

ConvertLower()
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringLower, Clipboard, Clipboard ;Convert case
	Len:= Strlen(Clipboard) ;Set number of characters
    	Send %Clipboard% ;Send new string
	Send +{left %Len%} ;Re-select text
    	VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave ;Restore previous clipboard
}
Also, I was able to find a list of words that should not be capitalized in titles. The list also includes special words in which some have letters that should all be capitalized, some with only a few letters capitalized, some with no letters ever capitalized, etc. This is it below.

Code: Select all

"|. A |. An |. The | 3D| 3G| 3i| 4D| 4G| 4GL| a | AA| AAA| ABC| aboard | about| above| ABS| ACC | ACC,| ACC.| across| ADD,| ADD.| ADHD| after | against| ahk| AI | AIDS | AK | AL | along| also| AmEx | among| and | and,| AofI| AR | around| as | as,| ASCII | at | AutoHotkey| AZ | before| behind| below | beneath| beside| between| beyond| BlackBerry| BMGF| BOD | BS | BS,| BS.| BSA | BSA,| BSA.| BSD | BSD,| BSD.| but | but,| by | c/o| CA | CA | CA,| CBS | cc | CD | CDC | CDD| CDT | CO | Co.| CPR | CST | CT | DBA | DC | DE | DHTML | DNA | down | during| DVD | eBay| EDT | ESP | ESPN| EST | EU | except | except,| FBI| FedEx| FL | FM| for | FPS | from | FUBAR| FUD | FYI | GA | GB| GM | GNU| GQ| GS |  HMO | HP | IA | IBM| ID | IL | iMac| in | inside | inside,| into | iOS| iPad| iPhone| IPO | iPod| IRS | ISBN| ISP | ISSN| JP| KP| KQED| KS | KY | LA | LA,| LA.| LAX| LGBT| LSD| LSE| MA | MD | MDT| ME | MI | MILF| MLB| MN| MO | Mo. | MS | Ms. | MST| MT | MT,| Mt.| NBA| NBC| NC | ND| NDA| NE | near | NFL| NH| NJ| NM| nor | NRG| NRH| NRW| NV| NY | NY,| NY.| NYC| NYSE| NYT| of | off | OH | OJ | OJT| OK | OMFG| OMG| on | onto| OO | OO,| OO.| OOP | OOP,| OOP.| or | or,| OTOH| out | over | PA | PBS| PC | PDT| PG | PG&E| pm | POTS | POV | POW | PPM| PRC| PST| PTO | QED| R&D| RI | RIP | RISD| ROCS| ROTFL| RPM| RT | SC | SD | SEC | SF | SF,| SF.| SFO | SFO,| SFO.| SFSU| since | since,| SNAFU| SOB | SOL | SQL| SS | STD | STM | TBD | the | through | throughout| till | TLA | TLC | TM | TN | to | toward| TSA| TTM| TV | TX | UC | UCB | UCD| UCLA| UCSC| UCSD| UCSF| UFC| UK| under | UNESCO| UNIX| until| up | UPC| UPI | upon | UPS | URL| USA | USA | USA,| USA.| USA.| USAF| USAID| USB | USC | USD | USDA| USF | USMC| USPO | USSR| UT | UT | UV| UVA| UW| VA | VCR| VCT| VD| VFR| VH1| VHF| VLSI| VOX | VR | VT| VW| WA | WBA | WC| WI | with | within | without | WRHS| WSJ| WTF| WV| WWF| WWI| WWII| www.| WY | WYSIWYG| XC| XHTML| XML| XP| XV| XVI| XVII| XVIII| XX| XXX| YMCA| YMMD| YMMV| YTD| YWCA| ZZZ| ZZZZ| ZZZZZ| ZZZZZZ|.ahk|.biz|.co|.com|.gov|.ly|.org|.xxx|HTML|LinkedIn|NASDAQ|O/S|YouTube|"
Can someone help me and tell me what I need to add to my script so that it will be able to do a proper title case. It would be awesome if I could figure this out.
User avatar
JoeWinograd
Posts: 1411
Joined: 10 Feb 2014, 20:00

Re: Proper Capitalization of a Tile, Not Just Upper Case of All Words.  Topic is solved

13 Jan 2020, 16:46

Hi BannerStore,

I haven't studied your script, but based on your question's title and body, you may (or may not) find this article that I wrote to be helpful:

Exclude words when converting to "Title Case" - AutoHotkey Script

Regards, Joe
User avatar
Chunjee
Posts: 383
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re: Proper Capitalization of a Tile, Not Just Upper Case of All Words.

14 Jan 2020, 08:44

I thought to try this with biga.ahk to see if it would be easy or not. I was hoping to get it in a few lines but I felt a function was clearer so I ended up doing that instead.

Code: Select all

A := new biga()

blackListedWords := "|. A |. An |. The | 3D| 3G| 3i| 4D| 4G| 4GL| a | AA| AAA| ABC| aboard | about| above| ABS| ACC | ACC,| ACC.| across| ADD,| ADD.| ADHD| after | against| ahk| AI | AIDS | AK | AL | along| also| AmEx | among| and | and,| AofI| AR | around| as | as,| ASCII | at | AutoHotkey| AZ | before| behind| below | beneath| beside| between| beyond| BlackBerry| BMGF| BOD | BS | BS,| BS.| BSA | BSA,| BSA.| BSD | BSD,| BSD.| but | but,| by | c/o| CA | CA | CA,| CBS | cc | CD | CDC | CDD| CDT | CO | Co.| CPR | CST | CT | DBA | DC | DE | DHTML | DNA | down | during| DVD | eBay| EDT | ESP | ESPN| EST | EU | except | except,| FBI| FedEx| FL | FM| for | FPS | from | FUBAR| FUD | FYI | GA | GB| GM | GNU| GQ| GS |  HMO | HP | IA | IBM| ID | IL | iMac| in | inside | inside,| into | iOS| iPad| iPhone| IPO | iPod| IRS | ISBN| ISP | ISSN| JP| KP| KQED| KS | KY | LA | LA,| LA.| LAX| LGBT| LSD| LSE| MA | MD | MDT| ME | MI | MILF| MLB| MN| MO | Mo. | MS | Ms. | MST| MT | MT,| Mt.| NBA| NBC| NC | ND| NDA| NE | near | NFL| NH| NJ| NM| nor | NRG| NRH| NRW| NV| NY | NY,| NY.| NYC| NYSE| NYT| of | off | OH | OJ | OJT| OK | OMFG| OMG| on | onto| OO | OO,| OO.| OOP | OOP,| OOP.| or | or,| OTOH| out | over | PA | PBS| PC | PDT| PG | PG&E| pm | POTS | POV | POW | PPM| PRC| PST| PTO | QED| R&D| RI | RIP | RISD| ROCS| ROTFL| RPM| RT | SC | SD | SEC | SF | SF,| SF.| SFO | SFO,| SFO.| SFSU| since | since,| SNAFU| SOB | SOL | SQL| SS | STD | STM | TBD | the | through | throughout| till | TLA | TLC | TM | TN | to | toward| TSA| TTM| TV | TX | UC | UCB | UCD| UCLA| UCSC| UCSD| UCSF| UFC| UK| under | UNESCO| UNIX| until| up | UPC| UPI | upon | UPS | URL| USA | USA | USA,| USA.| USA.| USAF| USAID| USB | USC | USD | USDA| USF | USMC| USPO | USSR| UT | UT | UV| UVA| UW| VA | VCR| VCT| VD| VFR| VH1| VHF| VLSI| VOX | VR | VT| VW| WA | WBA | WC| WI | with | within | without | WRHS| WSJ| WTF| WV| WWF| WWI| WWII| www.| WY | WYSIWYG| XC| XHTML| XML| XP| XV| XVI| XVII| XVIII| XX| XXX| YMCA| YMMD| YMMV| YTD| YWCA| ZZZ| ZZZZ| ZZZZZ| ZZZZZZ|.ahk|.biz|.co|.com|.gov|.ly|.org|.xxx|HTML|LinkedIn|NASDAQ|O/S|YouTube|"
blackListedWordsArray := A.map(A.split(blackListedWords, "|"), A.trim) ;map to an array and trim any leading/trailing whitespace
inputText := "Here is a script that I pieced together from threads here and there on this forum. This script converts sentences so all letters are changed to upper case, to lower case, to a properly formatted title case"
clipboard := % fn_titleCaseExceptBlackList(inputText, blackListedWordsArray)
; => Here Is a Script That I Pieced Together from Threads Here and There on This Forum This Script Converts Sentences So All Letters Are Changed to Upper Case to Lower Case to a Properly Formatted Title Case
exitapp

; ~~~ functions ~~~
fn_titleCaseExceptBlackList(param_text, param_blackListedWordsArray)
{
	A := new biga()
	textArray := A.split(param_text, " ")
	casedArray := []
	
	for key, value in textArray {
		if (A.indexOf(param_blackListedWordsArray, value) == -1) {
			casedArray.push(A.startCase(value))
		} else {
			casedArray.push(value)
		}
	}
	return A.join(casedArray, " ")
}
By default this is not case sensitive so the input "aaa" will not be changed because it matches the case insensitive item "AAA"
Additional logic could be added to case input to the blacklist array.
User avatar
Chunjee
Posts: 383
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re: Proper Capitalization of a Tile, Not Just Upper Case of All Words.

15 Jan 2020, 13:41

BannerStore wrote:
13 Jan 2020, 13:48
(I would also love to add First Case (the first letter of all words are capitalized), Pascal case (first letter capitalized with spaces removed), Snake case (words separated by hyphen for file naming purposes), and Dot case (dots in between all the words) but I don't want to be greedy!)
added snake case to biga.ahk today.
Pascal case:

Code: Select all

A := new biga()
msgbox, % StrReplace(A.startCase("this is my example string")," ","")
; => "ThisIsMyExampleString"
dot case could be done by the following:

Code: Select all

A := new biga()
msgbox, % StrReplace(A.startCase("this is my example string")," ",".")
; => "This.Is.My.Example.String"
msgbox, % A.toLower(StrReplace(A.startCase("this is my example string")," ","."))
; => "this.is.my.example.string"
FanaticGuru
Posts: 1399
Joined: 30 Sep 2013, 22:25

Re: Proper Capitalization of a Tile, Not Just Upper Case of All Words.

15 Jan 2020, 18:47

Here is my take on the problem.

Code: Select all

MsgBox % TitleCase("united states of america and the republic for which it stands")

TitleCase(Haystack)
{
	static Excluded
	if !Excluded
	{
		Excluded := {}
		for key, word in StrSplit("the|of|and|for", "|")
			Excluded[word] := true
	}
	X:=1
	while (X := RegExMatch(Haystack, "(\W*)(\w+)", M, X+StrLen(M)))
		Excluded[M2] ? Result .= M1 M2 : Result .= M1 Format("{:T}", M2)
	return Result
}

Esc::ExitApp

I mainly wanted to see if I could get something that worked pretty good in one fairly efficient loop here:

Code: Select all

	while (X := RegExMatch(Haystack, "(\W*)(\w+)", M, X+StrLen(M)))
		Excluded[M2] ? Result .= M1 M2 : Result .= M1 Format("{:T}", M2)

The creating of the Excluded list ended up taking more lines of code than the actual working loop.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts

AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon

[Function] Timer - Create and Manage Timers
list
Posts: 166
Joined: 26 Mar 2014, 14:03
Contact:

Re: Proper Capitalization of a Tile, Not Just Upper Case of All Words.

16 Jan 2020, 18:09

Just in case my approach here with INI and various rules TitleCase()
BannerStore
Posts: 31
Joined: 06 Sep 2017, 19:29

Re: Proper Capitalization of a Tile, Not Just Upper Case of All Words.

17 Jan 2020, 12:50

Joe,

It took me a little bit more time but your code helped me a lot to figure out a way to finally do it. (I am a real newbie. I don't know things like when I should or should not put quotes around variables and strings.)

Thanks!

JoeWinograd wrote:
13 Jan 2020, 16:46
Hi BannerStore,

I haven't studied your script, but based on your question's title and body, you may (or may not) find this article that I wrote to be helpful:

Exclude Broken Link for safety words when converting to "Title Case" - AutoHotkey Script

Regards, Joe
User avatar
JoeWinograd
Posts: 1411
Joined: 10 Feb 2014, 20:00

Re: Proper Capitalization of a Tile, Not Just Upper Case of All Words.

17 Jan 2020, 14:13

You're welcome, BannerStore, I'm glad the article was helpful for you. Regards, Joe
BannerStore
Posts: 31
Joined: 06 Sep 2017, 19:29

Re: Proper Capitalization of a Tile, Not Just Upper Case of All Words.

18 Jan 2020, 05:48

Thank you for your help. It'll try to take a look at it tomorrow and see if I can figure out what you did and if necessary, I'll incorporate some of your best ideas into my script that I finally finished. I'll post what I have now but to be honest, it's not the most elegant script but it does the job.

[quote =FanaticGuru post_id=309882 time=1579132053 user_id=118]
Here is my take on the problem.

Code: Select all

MsgBox % TitleCase("united states of america and the republic for which it stands")

TitleCase(Haystack)
{
	static Excluded
	if !Excluded
	{
		Excluded := {}
		for key, word in StrSplit("the|of|and|for", "|")
			Excluded[word] := true
	}
	X:=1
	while (X := RegExMatch(Haystack, "(\W*)(\w+)", M, X+StrLen(M)))
		Excluded[M2] ? Result .= M1 M2 : Result .= M1 Format("{:T}", M2)
	return Result
}

Esc::ExitApp

I mainly wanted to see if I could get something that worked pretty good in one fairly efficient loop here:

Code: Select all

	while (X := RegExMatch(Haystack, "(\W*)(\w+)", M, X+StrLen(M)))
		Excluded[M2] ? Result .= M1 M2 : Result .= M1 Format("{:T}", M2)

The creating of the Excluded list ended up taking more lines of code than the actual working loop.

FG
[/quote]
BannerStore
Posts: 31
Joined: 06 Sep 2017, 19:29

Re: Proper Capitalization of a Tile, Not Just Upper Case of All Words.

18 Jan 2020, 06:08

Hi, Chunjee,

Sorry for the late reply but I didn't have much free time in the past few days to reply to what you did. I really appreciate the help.

However, what you did with your script is really outside my safe zone. I have no idea what an array is and didn't know any of the functions you used. So It's going to take some time for me to figure out what you are doing. To be honest, I have no clue at all. I'm not used to all the new functions that I've never seen before.

Here is the final form of the script that I made by piecing a few threads together.

Code: Select all

;                      **********************************************************
;                      *  Toggle Between Title Case, Uppercase, lowercase, etc. *
;                      **********************************************************

cycleNumber:= 1

^+!u::
If (cycleNumber==1)
{
	ConvertTitle()
	cycleNumber:= 2
}
Else If (cycleNumber==2)
{
	ConvertUpper()
	cycleNumber:= 3
}
Else If (cycleNumber==3)
{
	ConvertLower()
	cycleNumber:= 4
}
Else
{
	ConvertSentence()
	cycleNumber:= 1
}
Return


ConvertTitle()																		; Converts selection to title case.
{
	ExcludeFile:=A_ScriptDir . "\TitleCaseExclude.txt" 									; Retrieves a list of words excluded from capitalization (eg. conjunctions and prepositions).  List is stored in a text file.
	FileRead,Exclude,%ExcludeFile%													; Transfers words into a variable called Exclude
	
	clipSave := Clipboard															; We need to use the clipboard in this script but we don't want to erase its current contents.  The next 4 lines prevent this.
	Clipboard = 																	; We first save the clipboard to another variable for temporary storage and then empty the clipboard.
	SendInput, ^c 																	; We copy the text that we selected to the clipboard.
	ClipWait																		; Wait a little for the computer to copy the selection.  Without this, a few lines will run before the selected text gets copied into the clipboard.
	
	ClipboardFirstChar:=SubStr(Clipboard,1,1) 											; get first character
	StringUpper,ClipboardFirstChar,ClipboardFirstChar 									; capitalize first letter to use later
	StringUpper,ClipboardTitle,Clipboard,T 												; Capitalize the first letters of all words
	Loop,Parse,Exclude,`n,`r 														; Find all exclusions
		ClipboardTitle:=RegExReplace(ClipboardTitle,"i)\b" . A_LoopField . "\b",A_LoopField) 	; Change exclusions back to lower case
	Clipboard:=ClipboardFirstChar . SubStr(ClipboardTitle,2) 								; Capitalizes first word even if an exclusion
	SendInput %Clipboard%
	Len:= Strlen(Clipboard) 															;Set number of characters	
	Send +{left %Len%} 																;Re-select text
	VarSetCapacity(OutputText, 0) 													;free memory
	Clipboard := clipSave 															;Restore previous clipboard	
}

ConvertUpper()					; Sets all letters in selected words to uppercase.
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringUpper, Clipboard, Clipboard ;Convert case
	Len:= Strlen(Clipboard) ;Set number of characters
    	Send %Clipboard% ;Send new string
	Send +{left %Len%} ;Re-select text
    	VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave ;Restore previous clipboard
}

ConvertLower()					; Sets all letters in selected words to lowercase.
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringLower, Clipboard, Clipboard ;Convert case
	Len:= Strlen(Clipboard) ;Set number of characters
    	Send %Clipboard% ;Send new string
	Send +{left %Len%} ;Re-select text
    	VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave ;Restore previous clipboard
}

ConvertSentence()				; Capitalizes first letter of ALL words
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard
	SendInput, ^c ; Copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringUpper, Clipboard, Clipboard, T ;Convert case
	Clipboard := RegExReplace(Clipboard, "(((^|([.!?]+\s+))[a-z])| i | i')", "$u1")
	Len:= Strlen(Clipboard) ;Determine the number of characters
	Send %Clipboard% ;Send new string
	Send +{left %Len%} ;Re-select text
	VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave ;Restore previous clipboard
}
Chunjee wrote:
14 Jan 2020, 08:44
I thought to try this with biga.ahk Broken Link for safety to see if it would be easy or not. I was hoping to get it in a few lines but I felt a function was clearer so I ended up doing that instead.

Code: Select all

A := new biga()

blackListedWords := "|. A |. An |. The | 3D| 3G| 3i| 4D| 4G| 4GL| a | AA| AAA| ABC| aboard | about| above| ABS| ACC | ACC,| ACC.| across| ADD,| ADD.| ADHD| after | against| ahk| AI | AIDS | AK | AL | along| also| AmEx | among| and | and,| AofI| AR | around| as | as,| ASCII | at | AutoHotkey| AZ | before| behind| below | beneath| beside| between| beyond| BlackBerry| BMGF| BOD | BS | BS,| BS.| BSA | BSA,| BSA.| BSD | BSD,| BSD.| but | but,| by | c/o| CA | CA | CA,| CBS | cc | CD | CDC | CDD| CDT | CO | Co.| CPR | CST | CT | DBA | DC | DE | DHTML | DNA | down | during| DVD | eBay| EDT | ESP | ESPN| EST | EU | except | except,| FBI| FedEx| FL | FM| for | FPS | from | FUBAR| FUD | FYI | GA | GB| GM | GNU| GQ| GS |  HMO | HP | IA | IBM| ID | IL | iMac| in | inside | inside,| into | iOS| iPad| iPhone| IPO | iPod| IRS | ISBN| ISP | ISSN| JP| KP| KQED| KS | KY | LA | LA,| LA.| LAX| LGBT| LSD| LSE| MA | MD | MDT| ME | MI | MILF| MLB| MN| MO | Mo. | MS | Ms. | MST| MT | MT,| Mt.| NBA| NBC| NC | ND| NDA| NE | near | NFL| NH| NJ| NM| nor | NRG| NRH| NRW| NV| NY | NY,| NY.| NYC| NYSE| NYT| of | off | OH | OJ | OJT| OK | OMFG| OMG| on | onto| OO | OO,| OO.| OOP | OOP,| OOP.| or | or,| OTOH| out | over | PA | PBS| PC | PDT| PG | PG&E| pm | POTS | POV | POW | PPM| PRC| PST| PTO | QED| R&D| RI | RIP | RISD| ROCS| ROTFL| RPM| RT | SC | SD | SEC | SF | SF,| SF.| SFO | SFO,| SFO.| SFSU| since | since,| SNAFU| SOB | SOL | SQL| SS | STD | STM | TBD | the | through | throughout| till | TLA | TLC | TM | TN | to | toward| TSA| TTM| TV | TX | UC | UCB | UCD| UCLA| UCSC| UCSD| UCSF| UFC| UK| under | UNESCO| UNIX| until| up | UPC| UPI | upon | UPS | URL| USA | USA | USA,| USA.| USA.| USAF| USAID| USB | USC | USD | USDA| USF | USMC| USPO | USSR| UT | UT | UV| UVA| UW| VA | VCR| VCT| VD| VFR| VH1| VHF| VLSI| VOX | VR | VT| VW| WA | WBA | WC| WI | with | within | without | WRHS| WSJ| WTF| WV| WWF| WWI| WWII| www.| WY | WYSIWYG| XC| XHTML| XML| XP| XV| XVI| XVII| XVIII| XX| XXX| YMCA| YMMD| YMMV| YTD| YWCA| ZZZ| ZZZZ| ZZZZZ| ZZZZZZ|.ahk|.biz|.co|.com|.gov|.ly|.org|.xxx|HTML|LinkedIn|NASDAQ|O/S|YouTube|"
blackListedWordsArray := A.map(A.split(blackListedWords, "|"), A.trim) ;map to an array and trim any leading/trailing whitespace
inputText := "Here is a script that I pieced together from threads here and there on this forum. This script converts sentences so all letters are changed to upper case, to lower case, to a properly formatted title case"
clipboard := % fn_titleCaseExceptBlackList(inputText, blackListedWordsArray)
; => Here Is a Script That I Pieced Together from Threads Here and There on This Forum This Script Converts Sentences So All Letters Are Changed to Upper Case to Lower Case to a Properly Formatted Title Case
exitapp

; ~~~ functions ~~~
fn_titleCaseExceptBlackList(param_text, param_blackListedWordsArray)
{
	A := new biga()
	textArray := A.split(param_text, " ")
	casedArray := []
	
	for key, value in textArray {
		if (A.indexOf(param_blackListedWordsArray, value) == -1) {
			casedArray.push(A.startCase(value))
		} else {
			casedArray.push(value)
		}
	}
	return A.join(casedArray, " ")
}
By default this is not case sensitive so the input "aaa" will not be changed because it matches the case insensitive item "AAA"
Additional logic could be added to case input to the blacklist array.

Return to “Ask For Help”

Who is online

Users browsing this forum: adrian88888888, Albireo, Bing [Bot], HiSoKa, vsub, Yakshongas and 338 guests