Solved

classic asp Capital Case

Posted on 2011-09-20
5
537 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 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