主頁(yè) > 知識(shí)庫(kù) > ASP中實(shí)現(xiàn)字符部位類(lèi)似.NET里String對(duì)象的PadLeft和PadRight函數(shù)

ASP中實(shí)現(xiàn)字符部位類(lèi)似.NET里String對(duì)象的PadLeft和PadRight函數(shù)

熱門(mén)標(biāo)簽:辰溪地圖標(biāo)注 海南銀行智能外呼系統(tǒng)商家 許昌智能電銷(xiāo)機(jī)器人公司 上海浦東騰訊地圖標(biāo)注位置 遼寧銀行智能外呼系統(tǒng) 澳大利亞城市地圖標(biāo)注 遼寧正規(guī)電銷(xiāo)機(jī)器人 姜堰電銷(xiāo)機(jī)器人 電銷(xiāo)機(jī)器人違法了嗎

論壇里又有人問(wèn)起日期怎樣格式化為:2004-08-09 05:02:20這樣的格式:于是寫(xiě)了一個(gè)左(右)對(duì)齊的函數(shù).這函數(shù)等價(jià)于.NET里String對(duì)象的PadLeft和PadRight函數(shù)

Function PadLeft(Value,Length,sChar)
  Dim strText,I
  strText = String(Length,sChar)
  strText = strText  Value
  LeftPad = Right(strText,Length)
End Function

改一下最下面則為這樣:

Function PadRight(Value,Length,sChar)
  Dim strText,I
  strText = String(Length,sChar)
  strText = Value  strText
  LeftPad = Left(strText,Length)
End Function

使用例子:日期顯示

AA = year(now) "-" PadLeft(month(now),2,"0") "-" PadLeft(Day(now),2,"0") " " PadLeft(Hour(now),2,"0") ":" PadLeft(Minute(now),2,"0") ":" PadLeft(Second(now),2,"0")

萬(wàn)能時(shí)間補(bǔ)位代碼

Public Function ForMatDate(DateAndTime, Para) '格式化日期(日期時(shí)間,格式) 
Dim Y, M, D, H, F, S 
IF Not ISNumeric(Para) Or Not ISDate(DateAndTime) Then Exit Function 
Y = CStr(Year(DateAndTime)) 
M = CStr(Month(DateAndTime)):IF Len(M) = 1 Then M = "0"  M 
D = CStr(Day(DateAndTime)):IF Len(D) = 1 Then D = "0"  D 
H = CStr(Hour(DateAndTime)):IF Len(H) = 1 Then H = "0"  H 
F = CStr(Minute(DateAndTime)):IF Len(F) = 1 Then F = "0"  F 
S = CStr(Second(DateAndTime)):IF Len(S) = 1 Then S = "0"  S 
Select Case Para 
  Case "0" 
    ForMatDate = Y  "-"  M  "-"  D  " "  H  ":"  F  ":"  S 
  Case "1" 
    ForMatDate = Y  "-"  M  "-"  D  " "  H  ":"  F 
  Case "2" 
    ForMatDate = Y  "-"  M  "-"  D 
  Case "3" 
    ForMatDate = Y  "/"  M  "/"  D 
  Case "4" 
    ForMatDate = Y  "年"  M  "月"  D  "日" 
  Case "5" 
    ForMatDate = M  "-"  D  " "  H  ":"  F 
  Case "6" 
    ForMatDate = M  "/"  D 
  Case "7" 
    ForMatDate = M  "月"  D  "日" 
  Case "8" 
    ForMatDate = Y  "年"  M  "月" 
  Case "9" 
    ForMatDate = Y  "-"  M 
  Case "10" 
    ForMatDate = Y  "/"  M 
  Case "11" 
    ForMatDate = right(Y,2)  "-" M  "-"  D  " "  H  ":"  F 
  Case "12" 
    ForMatDate = right(Y,2)  "-" M  "-"  D 
  Case "13" 
    ForMatDate = M  "-"  D 
  Case Else 
    ForMatDate = DateAndTime 
End Select 
End Function 
Response.Write ForMatDate(Now,"2")

asp一段自動(dòng)補(bǔ)位的函數(shù)

function formatsn(getnum,getbit)
dim formatsnnum,formatsnpre,formatsnj
formatsnnum = getbit – len(getnum)
for formatsnj = 1 to formatsnnum
formatsnpre = formatsnpre  "0"
next
formatsn = formatsnpre  getnum
end function

使用方法

formatsn(getnum,getbit)

getnum 計(jì)數(shù)
getbit 共幾位

到此這篇關(guān)于ASP中實(shí)現(xiàn)字符部位類(lèi)似.NET里String對(duì)象的PadLeft和PadRight函數(shù)的文章就介紹到這了,更多相關(guān)asp PadLeft和PadRight內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

標(biāo)簽:晉城 銅川 崇左 深圳 西藏 伊春 威海 撫州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP中實(shí)現(xiàn)字符部位類(lèi)似.NET里String對(duì)象的PadLeft和PadRight函數(shù)》,本文關(guān)鍵詞  ASP,中,實(shí)現(xiàn),字符,部位,類(lèi)似,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ASP中實(shí)現(xiàn)字符部位類(lèi)似.NET里String對(duì)象的PadLeft和PadRight函數(shù)》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于ASP中實(shí)現(xiàn)字符部位類(lèi)似.NET里String對(duì)象的PadLeft和PadRight函數(shù)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章