Bah, the code, the code:
<%
' ================================================== ===============
' Reformat "txtName" to proper case.
' Output = String
' ================================================== ===============
Function ProperName(txtName)
Dim txtRest, txtTmp, intSpcPos
txtRest = LCase(txtName)
'Single Quote
intTckPos = InStr(1, txtRest, "'",1)
if intTckPos <> 0 then
txtTmp = UCase(Mid(txtRest, intTckPos + 1, 1))
txtRest = Left(txtRest, intTckPos) & txtTmp & Mid(txtRest, intTckPos
+ 2, Len(txtRest))
txtTmp = ""
end if
'Hypenated
intDshPos = InStr(1, txtRest, "-",1)
if intDshPos <> 0 then
txtTmp = UCase(Mid(txtRest, intDshPos + 1, 1))
txtRest = Left(txtRest, intDshPos) & txtTmp & Mid(txtRest, intDshPos
+ 2, Len(txtRest))
txtTmp = ""
end if
'MC
intMcPos = InStr(1,txtRest,"mc",1)
if intMcPos <> 0 then
txtTmp = UCase(Mid(txtRest, intMcPos+2, 1))
txtRest = Left(txtRest, intMcPos+1) & txtTmp & Mid(txtRest,
intMcPos+3, Len(txtRest))
txtTmp = ""
end if
'Space
intSpcPos = InStr(1, txtRest, " ")
Do While intSpcPos <> 0
txtTmp = txtTmp & UCase(Left(txtRest, 1)) & Mid(txtRest,
2,(intSpcPos - 1))
txtRest = Mid(txtRest, intSpcPos + 1, Len(txtRest))
intSpcPos = InStr(1, txtRest, " ")
Loop
'Output
ProperName = txtTmp & UCase(Left(txtRest, 1)) & Mid(txtRest,
2,Len(txtRest))
End Function
' ================================================== ===============
%>
"Ken Fine" <ke*****@u.washington.edu> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
No joy on Macromedia's boards after a few days; maybe someone can help me
here.
I got an excellent string handling function off of planet-source-code.com
that converts text strings to proper case, i.e. "the REMAINS of the DAY"
is converted to "The Remains Of The Day".
This function is particularly good in that it handles certain exceptions.
Can you help me make it handle more? I'm interested in two tweaks, one
easy, one hard.
The easy tweak: I have certain acronyms that I'd always like to NOT be
converted into proper case -- I want them all upper. For instance,
"ASCII", "SCSI" and "IDE" shouldn't be rendered as "Ascii" "Scsi" and "Ide". The
list of exceptions is short and I'd be fine hardcoding them into the function.
The hard tweak: Certain "noise words" such as "is" "and" and "but" don't
belong in proper case. I don't want them capitalized at all UNLESS they're
the first word in the string.
Can any stringmeisters take a crack at this? Code appears below. If anyone
can help out with at least the first item, I'd be most appreciative.
-KF
Adjusting string handling function for exceptions?