网络编程
位置:首页>> 网络编程>> Asp编程>> 转换字符串单词的第一个字母为大写

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

  发布时间:2007-10-18 10:50:00 

标签:大写,字符串

本文介绍了一种将英文字符首个字母串转换为大写的asp代码,当然这个功能可能英文网站比较有用。

转换大写功能英文介绍:
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:

实现转换大写的asp函数代码:


<% 
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> 
转换字符串单词的第一个字母大写使用方法:<br> 
读取数据库字段例子: <%=PCase(rs("PG"))%> <br> 
读取asp参数.: <%=PCase(myVariable)%> <br> 
直接写入字符串.: <%=PCase("asp之家 www.aspxhome.com")%> <br> 
</body></html> 


0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com