转换字符串单词的第一个字母为大写-ASP技术-3P代码网
繁体中文
设为首页
加入收藏
当前位置:ASP技术首页 >> ASP技巧 >> 转换字符串单词的第一个字母为大写

转换字符串单词的第一个字母为大写

2004-10-01 08:26:10  作者:  来源:互联网  浏览次数:29  文字大小:【】【】【
简介:Code Title: Proper Case Description: You know how to use UCase and LCase, now here's Pcase! Ucase converts a string to all UPPERCASE, and of course Lcase does the opposite, but this will convert ...

Code Title: Proper Case

Description: You know how to use UCase and LCase, now here's Pcase! Ucase converts a string to all

UPPERCASE, and of course Lcase does the opposite, but this will convert any text string to Proper Case. It

basically capitalizes the first letter of every word in the string. Pretty cool, huh?!

Copy and paste this snippet as-is into your editor:

<%

Function PCase(strInput)

iPosition = 1

Do While InStr(iPosition, strInput, " ", 1) <> 0

iSpace = InStr(iPosition, strInput, " ", 1)

strOutput = strOutput & UCase(Mid(strInput, iPosition, 1))

strOutput = strOutput & LCase(Mid(strInput, iPosition + 1, iSpace - iPosition))

iPosition = iSpace + 1

Loop

strOutput = strOutput & UCase(Mid(strInput, iPosition, 1))

strOutput = strOutput & LCase(Mid(strInput, iPosition + 1))

PCase = strOutput

End Function

%>

Then, in your asp, use the function like this:

i.e.: <%=PCase(rs("PG"))%> or..

i.e.: <%=PCase(myVariable)%> etc etc etc..

责任编辑:admin
相关文章