深圳升蓝软件
数据库开发 .Net技术  |  ASP技术 PHP技术 JSP技术 应用技术类   
Hiblue Software

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


March 25,2004
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
%>

<html><body>
Then, in your asp, use the function like this:<br>
i.e.: <%=PCase(rs("PG"))%> or..<br>
i.e.: <%=PCase(myVariable)%> etc etc etc..<br>
</body></html>

       
Copyright © 2001-2008 Shenzhen Hiblue Software Team All rights reserved