PDA

View Full Version : Capitals


Leeus
11-28-2002, 05:27 PM
Hello all, I have a string which is a user name and is in the format JOE.BLOGGS, I have managed to do a replace on the dot so it now is JOE BLOGGS, is there any way to make it Joe Bloggs so that all but first letters are capitals?

whammy
11-28-2002, 08:07 PM
More string manipulation...:


<% @Language="VBScript" %>
<% Option Explicit %>
<%
Dim str, strarray, i
str = "JOE BLOGGS"
strarray = Split(str," ")
For i = 0 to UBound(strarray)
strarray(i) = UCase(Left(strarray(i),1)) & LCase(Right(strarray(i),Len(strarray(i))-1))
Next
str = Join(strarray," ")
Response.Write(str)
%>

whammy
11-28-2002, 08:17 PM
Even better?:

<% @Language="VBScript" %>
<% Option Explicit %>
<%
Function ExtractValidNameChars(byVal str) ''''''''
If IsNull(str) Then str = ""
Dim evncRegEx
Set evncRegEx = New RegExp
evncRegEx.Pattern = "[^a-z\.\,\\' ]"
evncRegEx.Global = True
evncRegEx.IgnoreCase = True
ExtractValidNameChars = evncRegEx.Replace(str,"")
End Function '''''''''''''''''''''''''''''''''''''

Function FormatName(byVal str) '''''''''''''''''''
Dim strarray, nameloop1, quotearray, nameloop2
str = ExtractValidNameChars(str)
strarray = Split(str," ")
For nameloop1 = 0 to UBound(strarray)
quotearray = Split(strarray(nameloop1),"'")
For nameloop2 = 0 to UBound(quotearray)
quotearray(nameloop2) = UCase(Left(quotearray(nameloop2),1)) & LCase(Right(quotearray(nameloop2),Len(quotearray(nameloop2))-1))
Next
strarray(nameloop1) = Join(quotearray,"'")
Next
FormatName = Trim(RemoveExtraSpaces(Join(strarray," ")))
End Function '''''''''''''''''''''''''''''''''''''

Function RemoveExtraSpaces(str) ''''''''''''''''''
If IsNull(str) Then str = ""
Dim resRegEx
Set resRegEx = New RegExp
resRegEx.Pattern = "\s+"
resRegEx.Global = True
RemoveExtraSpaces = resRegEx.Replace(str," ")
End Function '''''''''''''''''''''''''''''''''''''

Response.Write(FormatName("# MR. @#$ JOHN J. O'REILLY, SR. 4 "))
%>


Output:

Mr. John J. O'Reilly, Sr.

:D