Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making First Letters Upper Case in a String

Status
Not open for further replies.

Krus1972

Programmer
Mar 18, 2004
145
US
I have the following string:

list = "nintendo games;blackberry phone;baby toys"

I have tried developing several small ASP scripts with no success that will parse the above string and make only the first letter of each word upper case. I am trying to achieve the following output:

Nintendo Games
Blackberry Phone
Baby Toys

I am at a lost here because everything I develop produces the following output:

NiNteNdo Games
BlackBerry Phone
BaBy Toys


Can anyone help?

Thanks




 
Something like this might work:

Use the split function on semicolons to turn the string into an array of phrases.

phrasearray = split(list, ";")

Loop through the phrase array and split array elements on spaces to get arrays of words.

Loop through the word arrays and convert to proper case:

wordarray(i) = UCase(left(wordarray(i), 1) & LCase(Right(wordarray(i), len(wordarray(i)) - 1)

After the words loop is done reconstruct each phrase with join(word, " ")

Then move on to the next phrase.
 
There are several VBScript versions of the TitleCase function. Google found this one first:

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
try this simple one:
i think tsuji or one of the other guru's gave me this one
Code:
data = "THIS IS DATA, AS YOU CAN SEE THE WORDS" & " before conversion"
wscript.echo data
With New RegExp
	.Global = True
	.IgnoreCase = True

	.Pattern = "\b(\w)(\w*?)\b"
	WScript.echo .Replace(data, GetRef("ProperCase")) & " after conversion"

	.Pattern = "\b([a-z])([a-z]*?)\b"
	WScript.echo .Replace(data, GetRef("ProperCase")) & " after conversion" 
End With

Function ProperCase(match, submatch1, submatch2, index, source)
ProperCase = UCase(submatch1) & LCase(submatch2)
End Function
 
Is it simply for output in HTML? If it's merely style, then use the CSS transformation:

text-transform:capitalize
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top