• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

可以把文章标题中的英文单词的首字母变成大写的函数

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 40次 | 进入软件测试论坛讨论

领测软件测试网 功能说明:

可以把文章标题中的英文单词的首字母变成大写:)

效果演示:





<%

function PCase(strInput)
‘’Variable declaration.
Dim strArr
Dim tmpWord
Dim tmpString
Dim last


‘’Create an array To store Each word In the String separately.
strArr = split(strInput," ")


if ubound(strArr) > 0 Then
For x = lbound(strArr) To ubound(strArr)
‘’Set Each word To lower Case initially.
strArr(x) = LCase(strArr(x))


‘’Skip the unimportant words.
Select Case strArr(x)
Case "a"
Case "an"
Case "and"
Case "but"
Case "by"
Case "for"
Case "in"
Case "into"
Case "is"
Case "of"
Case "off"
Case "on"
Case "onto"
Case "or"
Case "the"
Case "to"
Case "a.m."
strArr(x) = "A.M."
Case "p.m."
strArr(x) = "P.M."
Case "b.c."
strArr(x) = "B.C."
Case "a.d."
strArr(x) = "A.D."
Case Else

‘’Capitalize the first letter, but don‘’t forget To take into account that
‘’the String may be in Single or Double quotes.
if len(strArr(x)) > 1 Then
if mid(strArr(x),1,1) = "‘’" or mid(strArr(x),1,1) = """" Then
tmpWord = mid(strArr(x),1,1) & Ucase(mid(strArr(x),2,1)) & mid(strArr(x),3,len(strArr(x))-2)
Else
tmpWord = Ucase(mid(strArr(x),1,1)) & mid(strArr(x),2,len(strArr(x))-1)
End if
strArr(x) = tmpWord
End if

End Select


‘’The unimportant words may need To be capitalized if they follow a dash, colon,
‘’semi-colon, Single quote or Double quote.
if x > 0 Then
if instr(strArr(x-1),"-") _
or instr(strArr(x-1),":") _
or instr(strArr(x-1),";") Then
tmpWord = Ucase(mid(strArr(x),1,1)) & mid(strArr(x),2,len(strArr(x))-1)
strArr(x) = tmpWord
End if
End if

Next
Else
strArr(0) = LCase(strArr(0))
End if


‘’Make sure the first word In the array is upper case, but don‘’t forget To take into account
‘’that the String may be in Single or Double quotes.
if mid(strArr(0),1,1) = "‘’" or mid(strArr(0),1,1) = """" Then
tmpWord = mid(strArr(0),1,1) & Ucase(mid(strArr(0),2,1)) & mid(strArr(0),3,len(strArr(0))-2)
Else
tmpWord = Ucase(mid(strArr(0),1,1)) & mid(strArr(0),2,len(strArr(0))-1)
End if
strArr(0) = tmpWord


‘’Also, make sure the last word In the array is upper case, but don‘’t forget To take into account
‘’that the String may be in Single or Double quotes.
last = ubound(strArr)
if mid(strArr(last),1,1) = "‘’" or mid(strArr(last),1,1) = """" Then
tmpWord = mid(strArr(last),1,1) & Ucase(mid(strArr(last),2,1)) & mid(strArr(0),3,len(strArr(last))-2)
Else
tmpWord = Ucase(mid(strArr(last),1,1)) & mid(strArr(last),2,len(strArr(last))-1)
End if
strArr(last) = tmpWord


‘’Rebuild the whole String from the array parts.
For x = lbound(strArr) To ubound(strArr)
tmpString = tmpString & strArr(x) & " "
Next

PCase = tmpString
End function
%>

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网