Solved

classic asp Capital Case

Posted on 2011-09-20
5
546 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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

820 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