Since I was working on Javascript I wanted to find "Title Case".
Here is my code which I am just adding to the board so I can remember to always google search first.
And also a link to a whole bunch of other better samples of Capitalize:
http://www.purebasic.fr/english/viewtop ... 35#p370335
My shame code (if you use it, it also deletes spaces between words ):
Code: Select all
EnableExplicit
Procedure.s capitalize(string$)
Protected n,i,phrase.s=LCase(string$),done.s = "Regx ERROR!",Dim wordsA.s(0)
Protected rx=CreateRegularExpression(#PB_Any, "[a-z][^\s]*")
If rx >0
n = ExtractRegularExpression(rx, phrase, wordsA())
If n > 1
done=""
For i = 0 To n - 1
done= done+UCase(Left(wordsA(i),1))+Mid(wordsA(i),2)+" "
Next
done=Left(done,Len(done)-1)
Else
done=UCase(Left(phrase,1))+Mid(phrase,2)
EndIf
FreeRegularExpression(rx)
EndIf
ProcedureReturn done
EndProcedure
Debug capitalize("Take any CASE and capitalize each word.")
Debug capitalize("another phrase. To convert")
Debug capitalize("and here's another, one")
Debug capitalize("a")
Debug capitalize("SINGLE")
Norm.