
Code: Select all
Macro AddExcludedWord(_Word_) : AddElement(ExcludedWords$()) : ExcludedWords$() = _Word_ : EndMacro
Procedure.b ListContainsString(List List$(), String$)
String$ = LCase(String$)
ForEach List$()
If LCase(List$()) = String$ : ProcedureReturn #True : EndIf
Next
ProcedureReturn #False
EndProcedure
; Converts a string to title case, respecting all the semantic rules that come along with that. For example, the at the very beginning of the string is capitalized, but anywhere else it isn't.
Procedure$ Capitalize(String$)
Protected.i i, Count
Protected Res$, Word$, FirstCharacter$, WordTail$
Static NewList ExcludedWords$()
AddExcludedWord("a")
AddExcludedWord("an")
AddExcludedWord("the")
AddExcludedWord("and")
AddExcludedWord("but")
AddExcludedWord("or")
AddExcludedWord("for")
AddExcludedWord("nor")
AddExcludedWord("on")
AddExcludedWord("at")
AddExcludedWord("to")
AddExcludedWord("by")
AddExcludedWord("of")
AddExcludedWord("in")
AddExcludedWord("up")
AddExcludedWord("with")
AddExcludedWord("as")
Count = CountString(String$, " ") + 1
For i = 1 To Count
Word$ = StringField(String$, I, " ")
FirstCharacter$ = Left(Word$, 1)
WordTail$ = Right(Word$, Len(Word$) - 1)
If i = 1 Or Not ListContainsString(ExcludedWords$(), Word$) : FirstCharacter$ = UCase(FirstCharacter$) : EndIf
Word$ = FirstCharacter$ + WordTail$
Res$ + Word$ + " "
Next
Res$ = RTrim(Res$, " ")
ProcedureReturn Res$
EndProcedure