|
 |
asp_web_howto thread: CapitalizeFirstLetter
Message #1 by "Sertial, Sam" <2495XX2@a...> on Tue, 27 Mar 2001 17:46:40 -0500
|
|
This function works fine if a "-" between a name (jack-Taylor), Can any body
help in altering the code to include other
characters like (space" ") or (') like O'brian to capitalize "O" and "B".
Thanks
Function CapLastName(lName)
dim a, s
a = split(lName, "-")
lName = ""
For each s in a
lName = lName & UCase(left(s,1))& LCase(Mid(s,2)) & "-"
Next
lName = Left(lName,Len(lName)-1)
CapLastName = lName
End function
Message #2 by Darren Wogan <darrenw@s...> on Wed, 28 Mar 2001 13:00:02 +0100
|
|
Try the following, which capitalises after a space. Sorry its not a mod on
your existing code, but could be modified to accomodate your current need
for capitalising after a '-' and a "'", which it doesn't currently do:
'###
'# Convert String To Title-Case
'###
function toTitle(byVal baseStr)
dim firstChr
dim tmpStr
Dim regEx, Match, Matches, retStr
Dim strLen
Dim prevPos
const srchStr = " "
'# Cut space clutter around string and get 1st char
baseStr = LTrim(baseStr)
baseStr = RTrim(baseStr)
retStr = UCase(Left(baseStr, 1))
prevPos = 2
strLen = len(baseStr)
Set regEx = New RegExp '# Create regular expression.
regEx.Pattern = srchStr '# Set pattern.
regEx.IgnoreCase = True '# Set case insensitivity.
regEx.Global = True '# Set global applicability.
Set Matches = regEx.Execute(baseStr) '# Execute search.
For Each Match in Matches '# Iterate Matches collection.
'# Get character after space
retStr = retStr & LCase(Mid(baseStr, prevPos, (Match.FirstIndex
+ 2 - prevPos) ))
retStr = retStr & UCase(Mid(baseStr, (Match.FirstIndex + 2), 1))
'# Record starting point for next grab of string
prevPos = Match.FirstIndex + 3
Next
retStr = retStr & LCase(Mid(baseStr, prevPos))
toTitle = retStr
end function
No doubt someone else will tell me I should have done it better another
way....
-----Original Message-----
From: Sertial, Sam [mailto:2495XX2@a...]
Sent: 27 March 2001 23:47
To: ASP Web HowTo
Subject: [asp_web_howto] CapitalizeFirstLetter
This function works fine if a "-" between a name (jack-Taylor), Can any body
help in altering the code to include other
characters like (space" ") or (') like O'brian to capitalize "O" and "B".
Thanks
Function CapLastName(lName)
dim a, s
a = split(lName, "-")
lName = ""
For each s in a
lName = lName & UCase(left(s,1))& LCase(Mid(s,2)) & "-"
Next
lName = Left(lName,Len(lName)-1)
CapLastName = lName
End function
Message #3 by "Alex Shiell, ITS, EC, SE" <alex.shiell@s...> on Wed, 28 Mar 2001 13:36:19 +0100
|
|
just use the same function but split on '
eg change the function to something like this
Function CapLastName(lName, splitchar)
dim a, s
a = split(lName, splitchar)
lName = ""
For each s in a
lName = lName & UCase(left(s,1))& LCase(Mid(s,2)) &
splitchar
Next
lName = Left(lName,Len(lName)-1)
CapLastName = lName
End function
then call CapLastName("o'brien", "'")
Don't forget about Mc - as in McDonald or MacDonald (plenty of them here in
scotland!)
-----Original Message-----
From: Sertial, Sam [mailto:2495XX2@a...]
Sent: Tuesday, March 27, 2001 11:47 PM
To: ASP Web HowTo
Subject: [asp_web_howto] CapitalizeFirstLetter
This function works fine if a "-" between a name (jack-Taylor), Can any body
help in altering the code to include other
characters like (space" ") or (') like O'brian to capitalize "O" and "B".
Thanks
Function CapLastName(lName)
dim a, s
a = split(lName, "-")
lName = ""
For each s in a
lName = lName & UCase(left(s,1))& LCase(Mid(s,2)) & "-"
Next
lName = Left(lName,Len(lName)-1)
CapLastName = lName
End function
________________________________________________________________________
Scottish Enterprise Network
http://www.scottish-enterprise.com
Message #4 by "Peter Lanoie" <planoie@e...> on Wed, 28 Mar 2001 09:05:28 -0500
|
|
If you are just looking to do proper capitalization:
sMyString = "my lower case string"
sMyString = StrConv(sMyString, vbProperCase)
'now sMyString = "My Lower Case String"
Also:
vbUpperCase (1) Converts the string to uppercase characters.
vbLowerCase (2) Converts the string to lowercase characters.
vbProperCase (3) Converts the first letter of every word in string to
uppercase.
-----Original Message-----
From: Sertial, Sam [mailto:2495XX2@a...]
Sent: Tuesday, March 27, 2001 5:47 PM
To: ASP Web HowTo
Subject: [asp_web_howto] CapitalizeFirstLetter
This function works fine if a "-" between a name (jack-Taylor), Can any body
help in altering the code to include other
characters like (space" ") or (') like O'brian to capitalize "O" and "B".
Thanks
Function CapLastName(lName)
dim a, s
a = split(lName, "-")
lName = ""
For each s in a
lName = lName & UCase(left(s,1))& LCase(Mid(s,2)) & "-"
Next
lName = Left(lName,Len(lName)-1)
CapLastName = lName
End function
Message #5 by Darren Wogan <darrenw@s...> on Wed, 28 Mar 2001 16:01:32 +0100
|
|
Peter,
Isn't StrConv() limited to VBA (Visual Basic for Applications) or pure VB,
rather than VBS (VBScript) which is what you'd be dealing with in ASP ?
Perhaps IIS 5/Win2K provides this (I'm using IIS 4/NT4 Server with Visual
InterDev 6). However my latest MSDN (Jan 01) lists this as VBA/VB only.
-----Original Message-----
From: Peter Lanoie [mailto:planoie@e...]
Sent: 28 March 2001 15:05
To: ASP Web HowTo
Subject: [asp_web_howto] RE: CapitalizeFirstLetter
If you are just looking to do proper capitalization:
sMyString = "my lower case string"
sMyString = StrConv(sMyString, vbProperCase)
'now sMyString = "My Lower Case String"
Also:
vbUpperCase (1) Converts the string to uppercase characters.
vbLowerCase (2) Converts the string to lowercase characters.
vbProperCase (3) Converts the first letter of every word in string
to
uppercase.
-----Original Message-----
From: Sertial, Sam [mailto:2495XX2@a...]
Sent: Tuesday, March 27, 2001 5:47 PM
To: ASP Web HowTo
Subject: [asp_web_howto] CapitalizeFirstLetter
This function works fine if a "-" between a name (jack-Taylor), Can any body
help in altering the code to include other
characters like (space" ") or (') like O'brian to capitalize "O" and "B".
Thanks
Function CapLastName(lName)
dim a, s
a = split(lName, "-")
lName = ""
For each s in a
lName = lName & UCase(left(s,1))& LCase(Mid(s,2)) & "-"
Next
lName = Left(lName,Len(lName)-1)
CapLastName = lName
End function
Message #6 by "Morgan, Rob" <Rob.Morgan@o...> on Wed, 28 Mar 2001 10:10:22 -0500
|
|
Here is a function that might help, may need work for special cases.
Public function ProperCase(sString)
Dim sWhiteSpace, bCap, iCharPos, sChar
sWhiteSpace = Chr(32) & Chr(9) & Chr(13) & "'"
sString = LCase(sString)
bCap = True
For iCharPos = 1 to Len(sString)
sChar = Mid(sString, iCharPos, 1)
If bCap = True Then
sChar = UCase(sChar)
End If
ProperCase = ProperCase + sChar
If InStr(sWhiteSpace, sChar) Then
bCap = True
Else
bCap = False
End If
Next
End Function
-----Original Message-----
From: Darren Wogan [mailto:darrenw@s...]
Sent: Wednesday, March 28, 2001 10:02 AM
To: ASP Web HowTo
Cc: 'Peter Lanoie'
Subject: [asp_web_howto] RE: CapitalizeFirstLetter
Peter,
Isn't StrConv() limited to VBA (Visual Basic for Applications) or pure VB,
rather than VBS (VBScript) which is what you'd be dealing with in ASP ?
Perhaps IIS 5/Win2K provides this (I'm using IIS 4/NT4 Server with Visual
InterDev 6). However my latest MSDN (Jan 01) lists this as VBA/VB only.
-----Original Message-----
From: Peter Lanoie [mailto:planoie@e...]
Sent: 28 March 2001 15:05
To: ASP Web HowTo
Subject: [asp_web_howto] RE: CapitalizeFirstLetter
If you are just looking to do proper capitalization:
sMyString = "my lower case string"
sMyString = StrConv(sMyString, vbProperCase)
'now sMyString = "My Lower Case String"
Also:
vbUpperCase (1) Converts the string to uppercase characters.
vbLowerCase (2) Converts the string to lowercase characters.
vbProperCase (3) Converts the first letter of every word in string
to
uppercase.
-----Original Message-----
From: Sertial, Sam [mailto:2495XX2@a...]
Sent: Tuesday, March 27, 2001 5:47 PM
To: ASP Web HowTo
Subject: [asp_web_howto] CapitalizeFirstLetter
This function works fine if a "-" between a name (jack-Taylor), Can any body
help in altering the code to include other
characters like (space" ") or (') like O'brian to capitalize "O" and "B".
Thanks
Function CapLastName(lName)
dim a, s
a = split(lName, "-")
lName = ""
For each s in a
lName = lName & UCase(left(s,1))& LCase(Mid(s,2)) & "-"
Next
lName = Left(lName,Len(lName)-1)
CapLastName = lName
End function
Message #7 by "Peter Lanoie" <planoie@e...> on Wed, 28 Mar 2001 11:24:21 -0500
|
|
Darren,
I think perhaps you're right. I switch back and forth between writing ASP
and VB in components, that I loose track. If this is something you're
getting out of a database, there is a SQL function that does propercase. I
found it once, but don't remember, nor have I been able to find it.
-----Original Message-----
From: Darren Wogan [mailto:darrenw@s...]
Sent: Wednesday, March 28, 2001 10:02 AM
To: ASP Web HowTo
Cc: 'Peter Lanoie'
Subject: [asp_web_howto] RE: CapitalizeFirstLetter
Peter,
Isn't StrConv() limited to VBA (Visual Basic for Applications) or pure VB,
rather than VBS (VBScript) which is what you'd be dealing with in ASP ?
Perhaps IIS 5/Win2K provides this (I'm using IIS 4/NT4 Server with Visual
InterDev 6). However my latest MSDN (Jan 01) lists this as VBA/VB only.
-----Original Message-----
From: Peter Lanoie [mailto:planoie@e...]
Sent: 28 March 2001 15:05
To: ASP Web HowTo
Subject: [asp_web_howto] RE: CapitalizeFirstLetter
If you are just looking to do proper capitalization:
sMyString = "my lower case string"
sMyString = StrConv(sMyString, vbProperCase)
'now sMyString = "My Lower Case String"
Also:
vbUpperCase (1) Converts the string to uppercase characters.
vbLowerCase (2) Converts the string to lowercase characters.
vbProperCase (3) Converts the first letter of every word in string
to
uppercase.
-----Original Message-----
From: Sertial, Sam [mailto:2495XX2@a...]
Sent: Tuesday, March 27, 2001 5:47 PM
To: ASP Web HowTo
Subject: [asp_web_howto] CapitalizeFirstLetter
This function works fine if a "-" between a name (jack-Taylor), Can any body
help in altering the code to include other
characters like (space" ") or (') like O'brian to capitalize "O" and "B".
Thanks
Function CapLastName(lName)
dim a, s
a = split(lName, "-")
lName = ""
For each s in a
lName = lName & UCase(left(s,1))& LCase(Mid(s,2)) & "-"
Next
lName = Left(lName,Len(lName)-1)
CapLastName = lName
End function
Message #8 by "Sertial, Sam" <2495XX2@a...> on Wed, 28 Mar 2001 15:05:05 -0500
|
|
Thanks a lot Rob, your code worked fine and exactly what we looking for, I
added chr(45) and chr(47), is perfect. Thanks again and thanks to Alex,
Darren Wogan, Peter Lanoie who responded to my call.
-----Original Message-----
From: Morgan, Rob [mailto:Rob.Morgan@o...]
Sent: Wednesday, March 28, 2001 10:10 AM
To: ASP Web HowTo
Subject: [asp_web_howto] RE: CapitalizeFirstLetter
Here is a function that might help, may need work for special cases.
Public function ProperCase(sString)
Dim sWhiteSpace, bCap, iCharPos, sChar
sWhiteSpace = Chr(32) & Chr(9) & Chr(13) & "'"
sString = LCase(sString)
bCap = True
For iCharPos = 1 to Len(sString)
sChar = Mid(sString, iCharPos, 1)
If bCap = True Then
sChar = UCase(sChar)
End If
ProperCase = ProperCase + sChar
If InStr(sWhiteSpace, sChar) Then
bCap = True
Else
bCap = False
End If
Next
End Function
-----Original Message-----
From: Darren Wogan [mailto:darrenw@s...]
Sent: Wednesday, March 28, 2001 10:02 AM
To: ASP Web HowTo
Cc: 'Peter Lanoie'
Subject: [asp_web_howto] RE: CapitalizeFirstLetter
Peter,
Isn't StrConv() limited to VBA (Visual Basic for Applications) or pure VB,
rather than VBS (VBScript) which is what you'd be dealing with in ASP ?
Perhaps IIS 5/Win2K provides this (I'm using IIS 4/NT4 Server with Visual
InterDev 6). However my latest MSDN (Jan 01) lists this as VBA/VB only.
-----Original Message-----
From: Peter Lanoie [mailto:planoie@e...]
Sent: 28 March 2001 15:05
To: ASP Web HowTo
Subject: [asp_web_howto] RE: CapitalizeFirstLetter
If you are just looking to do proper capitalization:
sMyString = "my lower case string"
sMyString = StrConv(sMyString, vbProperCase)
'now sMyString = "My Lower Case String"
Also:
vbUpperCase (1) Converts the string to uppercase characters.
vbLowerCase (2) Converts the string to lowercase characters.
vbProperCase (3) Converts the first letter of every word in string
to
uppercase.
-----Original Message-----
From: Sertial, Sam [mailto:2495XX2@a...]
Sent: Tuesday, March 27, 2001 5:47 PM
To: ASP Web HowTo
Subject: [asp_web_howto] CapitalizeFirstLetter
This function works fine if a "-" between a name (jack-Taylor), Can any body
help in altering the code to include other
characters like (space" ") or (') like O'brian to capitalize "O" and "B".
Thanks
Function CapLastName(lName)
dim a, s
a = split(lName, "-")
lName = ""
For each s in a
lName = lName & UCase(left(s,1))& LCase(Mid(s,2)) & "-"
Next
lName = Left(lName,Len(lName)-1)
CapLastName = lName
End function
|
|
 |