Solved

classic asp Capital Case

Posted on 2011-09-20
5
562 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 54

Expert Comment

by:Huseyin KAHRAMAN
ID: 36570910
use a function like the one here:

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

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 29

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

734 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