asp中字串轉化為實體類的方法(最佳化篇,簡單最佳化)

來源:互聯網
上載者:User

option explicit<br />dim str1,str2<br />str1 ="order|||shiyang:100,mayang:200"<br />str2 = "book|||shuming:電腦,dingjia:100"<br />'聲明2個全域對象<br />'放棄了一開始希望用數組儲存的方式,那個雖然效率更高,但是需要自訂的array_pushobj函數,所以此處不做討論了<br />dim objname_g<br />dim classname_g<br />'返回實體類<br />function getObjmod(byval str)<br /> dim classname,itemlist,i<br /> dim execstr<br />classname = split(str,"|||")(0)<br /> execstr = "class "&classname&chr(10)<br /> itemlist = split(split(str,"|||")(1),",")<br /> for i = 0 to ubound(itemlist)<br /> execstr = execstr +"public "&split(itemlist(i),":")(0)&chr(13)&chr(10)<br /> next<br /> execstr = execstr&"end class"&chr(13)&chr(10)&_<br /> " set objname_g = new "&classname</p><p> classname_g =classname<br /> execute execstr</p><p>end function<br />'賦值<br />function getobjcon(byval str)<br />dim itemlist,i,execstr<br />if classname_g = split(str,"|||")(0) and isobject(objname_g) then<br />set getobjcon = objname_g<br />else<br />getObjmod( str)<br />set getobjcon = objname_g<br />end if<br /> itemlist = split(split(str,"|||")(1),",")<br /> for i = 0 to ubound(itemlist)<br /> execstr = execstr +"getobjcon."&split(itemlist(i),":")(0)&" = """&split(itemlist(i),":")(1)&"""" &chr(13)&chr(10)<br /> next<br /> execute execstr<br />end function<br />'測試函數<br />sub ceshi3<br />dim i,o1<br /> for i = 0 to 10000<br /> set o1 = getobjcon(str1)<br /> response.write o1.shiyang&"<br>"<br /> next<br /> set o1 = getobjcon(str2)<br /> response.write o1.shuming&"<br>"</p><p>end sub<br />dim t1<br />t1=timer()<br />call ceshi3<br />response.write FormatNumber((timer()-t1),4,-1)<br /> 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.