WJG <27/06/12> In a previous post I included an example of how to create formatted title strings using the selection in a Tk text widget. The following example shows how to create formatted titles using arbitrary strings.
exec tclsh "$0" "$@"
set exceptions "a an and are as at be for had has have have if in is of on or that the this to with you your"
proc capitalize {str1 {str2 {}} } {
foreach word $str1 {
if { [lsearch -exact $str2 $word] == -1 } {
set word [string totitle $word]
}
lappend text $word
}
return [string totitle $text 0 0]
}
puts [capitalize "the development of perfection -the interiorization of buddhist ritual in the eighth and ninth centuries" $exceptions]
puts [capitalize "vasubandhu's philosophical critique of the vatsiputriya's theory of persons (II)" $exceptions]
lappend exceptions (II)
puts [capitalize "vasubandhu's philosophical critique of the vatsiputriya's theory of persons (II)" $exceptions]
puts [capitalize "vasubandhu's philosophical critique of the vatsiputriya's theory of persons (II)"]