Back to blog

ASP equivalent to PHP Ucfirst function

This code does the same thing that Ucfirst function makes in PHP. “Ucfirst” means “Uppercase first letter”. ASP doesn’t have…

This code does the same thing that Ucfirst function makes in PHP. “Ucfirst” means “Uppercase first letter”. ASP doesn’t have this function natively:

function ucfirst(tname)
	ucfirst = ""
	tname = tname & " "
	do while instr(tname, " ")
		temp_string = left(tname, instr(tname," " ) -1)
		' ucase the first letter
		ucfirst = ucfirst & ucase(mid(temp_string, 1,1))
		' lcase for rest of word
		ucfirst = ucfirst & lcase(mid(temp_string,2)) & " "
		tname = right(tname, len(tname) - instr(tname," " ))
	loop
	'show me what i get
	ucfirst = ucfirst & ucase(mid(tname, 1,1))
	ucfirst = ucfirst & mid(tname,2)
	ucfirst = Trim(ucfirst)
end Function

Canonical URL