Solved

classic asp Capital Case

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

Expert Comment

by:disrupt
ID: 36570860
0
 
LVL 53

Expert Comment

by:Huseyin KAHRAMAN
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Aspx calendar pop up control 3 35
ASP.net Moving Visual Studio 2015 project to 2017 2 59
CSS question 16 57
Passing ASP variables in JQuery 4 48
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 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