Solved

classic asp Capital Case

Posted on 2011-09-20
5
519 Views
Last Modified: 2012-05-12
I have a data like los angeles and I would like to convert to Los Angeles

How can I do that in classic asp? I just need first letter is capital.
and the data came from sql server database.
0
Comment
Question by:Webboy2008
5 Comments
 
LVL 16

Expert Comment

by:disrupt
ID: 36570860
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 36570910
use a function like the one here:

http://www.4guysfromrolla.com/webtech/092798-1.shtml
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36571205
You can use this:

Function PCase(word)
    PCase = UCase(Left(word,1)) & LCase(Mid(word,2))
End Function

Then all you need to do is:

PCase(state) or whatever your form fieldname is.
0
 
LVL 11

Accepted Solution

by:
G_H earned 500 total points
ID: 36572654
Hi There,

I have two functions I use to do this...

They will work for you, but also work for people's names, such as "McDonald"...

Use as:

Str = "loS anGeles"
SortedText = ProperCase(Str)


 
'' ## Proper Case (Name Case) a sentance, or name
'' ## Uses PCaseWord to do the donkey work
Public Function ProperCase(Input)
	Dim strOut, astr, i, j, t

	strOut = LCase(Input)
	astr = Split(strOut, " ")

	for i = 0 to UBound(astr)
		if InStr(astr(i), "-") = 0 then
			astr(i) = PCaseWord(astr(i))
		else
			t = Split(astr(i), "-")
			for j = 0 to UBound(t)
				t(j) = PCaseWord(t(j))
			next
			astr(i) = Join(t, "-")
		end if
	next

	ProperCase = Join(astr, " ")
End Function

'' ## Takes a word and Upper-cases the first character, Also deals with "McDonnell", "MacDonalds" and "O'Riley"
Function PCaseWord(strIn)
	Dim strOut, t

	t = Mid(strIn, 1, 3)
	if t = "mac" then
		strOut = "Mac" & UCase(Mid(strIn, 4, 1)) & Mid(strIn, 5)
	else
		t = Mid(t, 1, 2)
		if t = "mc" then
			strOut = "Mc" & UCase(Mid(strIn, 3, 1)) & Mid(strIn, 4)
		elseif t = "o'" then
			strOut = "O'" & UCase(Mid(strIn, 3, 1)) & Mid(strIn, 4)
		else
			strOut = UCase(Mid(strIn, 1, 1)) & Mid(strIn, 2)
		end if
	end if

	PCaseWord = strOut
End Function

Open in new window


@sammy: I think your code will result in "Los angeles" rather than "Los Angeles"...?

GH
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36573502
Oops, you are right but it is a trivial fix:

Function PCase(word)
    PCase = UCase(Left(word,1)) & UCase(Mid(word,2))
End Function

Open in new window

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now