asp将每个单词的首个字母改成大写

时间:2009-03-25    点击:1563   
<%
'将Str中每个单词的首个字母改成大写
Public Function WordsUpper(Str)
Dim I, TempStr, Words, TempWords
Str = Trim(Str)
'以空格为分隔符,将字符串分成子字符串存入数组
    Words = Split(Str," ")
TempStr=""
    For I = 0 To UBound(Words)
'如果不是第一个单词,在前面加一个空格
        If I > 0 Then
            TempStr = " "
        End If
TempWords= Trim(Words(I))
If Len(TempWords)>0 Then
     '将单词的首个字母转换为大写
             TempStr = TempStr & UCase(Left(TempWords,1)) & Right(TempWords,(Len(TempWords)-1))
End If
        Words(I) = TempStr
    Next
    WordsUpper = ArrayToString(Words)
End Function
'将数组Array1转换为字符串
Public Function ArrayToString(ByVal Array1)
    Dim I, String1
    For I = 0 To UBound(Array1)
        String1 = String1 & Array1(I)
    Next
    ArrayToString = String1
End function
%>
<form name="form1" method="post" action="">
  输入单词:
  <input name="text" type="text" id="text" >
  <input type="submit" name="Submit" value="提交">
</form>
<%
Dim X
X=Request.Form("text")
If X<>"" Then
%>
<p>输入的单词:<%=X%></p>
<p>首个字母改成大写后为:<%=WordsUpper(X)%></p>
<%
End If
%>
asp判断字符是否是英文字符
asp检测字符串出现的次数
asp过滤字符串中的HTML代码
asp截取字符串
asp实现字符串和数组的转换
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 All Rights Reserved