Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: mixed case Uppercase first character of each word Propercase
;This Udf Converts A String From Random Mixed Case To "propercase" Where
; Only The First Words Of Strings Are Uppercase And The Rest Are Lowercase
;More advanced versions are loating around that understand quoted words,
;some words that do not get capitalized like the or of in strings,
;roman numerals, and common abbreviations. However all of those are
;very usage and language dependent.
#DefineFunction Propercase(sbad)
sbad=StrLower(sbad)
count=ItemCount(sbad," ")
sgood=""
For xx=1 To count
thisword=ItemExtract(xx,sbad," ")
thislen=StrLen(thisword)
If thislen > 1
thisword=StrCat(StrUpper(StrSub(thisword,1,1)),StrSub(thisword,2,-1))
Else
If thislen==1
thisword=StrUpper(thisword)
EndIf
EndIf
If sgood=="" Then sgood=thisword
Else sgood=StrCat(sgood," ",thisword)
Next
Return(sgood)
#EndFunction
TestString="tHis sTRing is Jacked"
FixedString=ProperCase(TestString)
Message(teststring,FixedString)
Here is a slightly smarter version that can handle normal capitalization exceptions - like some words are not capitalized, and some ancrnyms are fully capitalized.
CapLine="capitalize this like of characters the right way" origline=capline CapLine=StrTrim(StrLower(CapLine)) CapCount=ItemCount(CapLine," ") NewCapLine="" For capxx=1 To CapCount cw=ItemExtract(capxx,CapLine," ") If capxx==1 || ( capxx!=1 && cw!='a' && cw!="an" && cw!='to' && cw!='by' && cw!='the' && cw!='for' && cw!='and' && cw!='in' && cw!='about' && cw!='on' && cw!="of" && cw!="from" && cw!="with" && cw!="my" ) If StrLen(cw) >= 2 charone=StrUpper(StrSub(cw,1,1)) If charone=="'" || charone=='"' || charone=="`" cw=StrCat ( StrUpper(StrSub(cw,1,2)) , StrSub(cw,3,-1)) Else cw=StrCat ( charone , StrSub(cw,2,-1)) EndIf Else If StrLen(cw==1) Then cw=StrUpper(cw) EndIf EndIf cw2=StrReplace(cw,".","") cw2=StrReplace(cw2,",","") If cw2=="Bc" || cw2=="Ad" || cw2=="Ii" || cw2=="Iii" || cw2=="Iv" || cw2=="Vi" || cw2=="Vii" || cw2=="Viii" || cw2=="Ix" Then cw=StrUpper(cw) Newcapline=StrCat(newcapline,cw," ") Next CapLine=StrTrim(newcapline) Message(origline,capline)
Article ID: W15765
File Created: 2005:02:01:10:55:18
Last Updated: 2005:02:01:10:55:18