Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

captilize first character of last name string 2

Status
Not open for further replies.

onressy

Programmer
Mar 7, 2006
421
CA
I i'm using an array to create a format for a csv file.
The first name and last name fields somethimes do not have a capital letter at the begining, how could i change this?

For i = 0 To UBound(garrResult, 2)

Response.Write(garrResult(3, i)) ' E-mail
Response.Write(",")
Response.Write( Replace(garrResult(1, i), ",", "") ) ' Last Name
Response.Write(",")
Response.Write( Replace(garrResult(2, i), ",", "") ) ' First Name
Response.Write(",")
Response.Write(garrResult(6, i))
Response.Write(",")
Response.Write(garrResult(0, i))
Response.Write(",")
Response.Write(garrResult(9, i))
Response.Write(",")
Response.Write(garrResult(10, i))
Response.Write(vbCrLf)

Next

I've been trying things, without any luck, such as:
Response.Write( UCase(Left(Replace(garrResult(2, i), ",", ""))) ) ' First Name

any suggestions? Thanks
 
It's capitalizing the last name value but its truncating the last name at the Letter it's capitalizing, hence:
before trying to get it to capitalize the following was true:
Replace(garrResult(2, i), ",", "") = jones

now the following is true:
UCASE(Left(Replace(garrResult(2, i), ",", ""), 1 )) = J

I need to do the replace but also capitalize it at the same time, any suggestions? Thnx
 
then try this:

dim blah
blah=Replace(garrResult(2, i), ",", "")
UCASE(Left(blah, 1 )) & UCASE(Mid(blah, 2, len(blah)-1))

-DNG
 
oops...you dont need ucase in the later case

dim blah
blah=Replace(garrResult(2, i), ",", "")
UCASE(Left(blah, 1 )) & Mid(blah, 2, len(blah)-1)

-DNG
 
still no luck with that:

the code:

For i = 0 To UBound(garrResult, 2)

Response.Write(garrResult(3, i)) ' E-mail
Response.Write(",")
Response.Write( Replace(garrResult(2, i), ",", "") ) & " " & ( Replace(garrResult(1, i), ",", "") ) ' Name
Response.Write(",")

blah2=Replace(garrResult(1, i), ",", "")
UCASE(Left(blah2, 1 )) & UCASE(Mid(blah2, 2, len(blah2)-1))
Response.Write( blah2 )

'Response.Write(UCASE(Left(Replace(garrResult(1, i), ",", ""), 1)) ) ' Last Name
'Response.Write( Replace(garrResult(1, i), ",", "") ) ' Last Name
Response.Write(",")

blah=Replace(garrResult(2, i), ",", "")
UCASE(Left(blah, 1 )) & UCASE(Mid(blah, 2, len(blah)-1))
Response.Write( blah )

'Response.Write(UCASE(Left(Replace(garrResult(2, i), ",", ""), 1)) ) ' First Name
'Response.Write( Replace(garrResult(2, i), ",", "") ) ' First Name
Response.Write(",")
 
either way: UCASE(Mid or with just: Mid

get the same result that its not changing the letter to upper case..
 
Either your name is seth or there are a lot of people with this question around the world today :)

Easiest way to handle this would be to create a function toi do the work for you, and then just call that. Your pretty close to the solution. Basically you need to pull off the first letter, UCase it, then pull off everything but the first letter (and LCase it to make sure). The problem in your above code is that your not setting your variable equal to the UCase(...etc). UCase, LCase and etc return the value instead of changing the original one you sent, so you would need to do this:
Code:
blah2=Replace(garrResult(1, i), ",", "")
[highlight]blah2 = UCASE(Left(blah2, 1 )) & UCASE(Mid(blah2, 2, len(blah2)-1))[/highlight]
Response.Write( blah2 )

Embedding that in a function should be fairly easy:
Code:
Function PCase(str)
   PCase = UCase(Left(str,1)) & LCase(Right(str,Len(str)-1))
End Function

Hope this helps,
-T

barcode_1.gif
 
Thanks Tarwn, simple over-sight on my part
 

'****************************************************
' Function - doCaps - Capitalisation of Text
'****************************************************
Function doCaps (mytxt, mymode)
dim tbuff
dim nBuff
dim tchar
dim tAscii
dim n
nBuff = ""
tbuff = trim(mytxt)
if mymode = "First" then
For n = 1 To Len(tbuff)
tAscii = Asc(Mid(tbuff, n, 1))
If tAscii > 95 And tAscii < 123 Then
If n = 1 Then
tAscii = tAscii - 32
ElseIf Mid(tbuff, n - 1, 1) < "!" Then
tAscii = tAscii - 32
End If
End If
nBuff = nBuff & Chr(tAscii)
Next
elseif mymode = "All" then
nBuff = ucase(tBuff)
elseif mymode = "None" then
nBuff = lcase(tBuff)
else
nBuff = lcase(tBuff)
end if
doCaps = nBuff
End Function
 
I like tarwyn's solution using left and right. It's just a tiny bit simpler.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top