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

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 asilas 的 blog

 

功能说明:

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

效果演示:

 

<%

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
     

本文关键:首字母
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top