Visual_Basic 板


LINE

以下进行两种方法的效能比较 执行结果(共进行5次比较) 0.921875 2.375 0.90625 2.359375 1.640625 2.09375 1.21875 2.65625 1.546875 1.984375 第一种方法比较快 之前M氏提供的方法有错误喔,原po张贴的主题是VB6(应该没错吧?), VB6不支援阵列索引的字串,所以只有2种方法逐一存取字串中的每一个字元 →使用StrConv()转换成byte阵列直接存取 →Mid()函数 Mid()的效能较差,在回圈外使用还没关系,在回圈内大量使用会拖垮系统 regex的方式的话,对新手来说特别难理解吧...(虽然很好用 但比较不易学习) 我就不试了,因为我也不太了解regex的语法 衅 ─────────────────────────────────────── Option Explicit Sub test() Dim x As String Dim i As Double Dim st As Long st = Timer For i = 1 To 300000 x = rep1("aA...zZ ") Next Debug.Print (Timer - st), st = Timer For i = 1 To 300000 x = rep3("aA...zZ ") Next Debug.Print (Timer - st) End Sub Public Function rep1(ByVal src As String) If src = "" Then rep1 = "": Exit Function Dim i As Integer, b() As Byte b = StrConv(src, vbFromUnicode) Const c As Byte = 35 'Asc("#") = 35 For i = 0 To UBound(b) '65 ~ 90 大写英文字母 '97 ~ 122 小写英文字母 If (b(i) >= 65 And b(i) <= 90) Or (b(i) >= 97 And b(i) <= 122) Then b(i) = 35 End If Next rep1 = StrConv(b, vbUnicode) End Function Function rep3(s As String) As String Dim i As Integer Dim s2 As String Dim c As String For i = 1 To Len(s) c = Mid(s, i, 1) If (c >= "A" And c <= "Z") Or (c >= "a" And c <= "z") Then s2 = s2 + "#" Else s2 = s2 + c End If Next i rep3 = s2 End Function -- ▃▅▇▆▄ ▆▂▃ ` 逝去感如何能留住,半点遗留殊不易,██▅▇▄▃ ▇▃▂" . █████████▃i ▁▄▇ 更多凄凄惨惨的遭遇………██▆▃ █▅▆▃ˍ▄* ▂█▄▇▅▂. 我不知道,王~八~蛋~~! ▂▆███ █▄▃ 。fumizuki。Check。 --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.194.106.250
1F:→ MOONRAKER:好吧,s(i)取字元的写法才真的是过时20年的写法 X( 03/07 12:23
2F:→ MOONRAKER:以前是在干嘛怎麽都没注意到 X( 03/07 12:23
3F:推 MOONRAKER:版主的比较则是明确指出 + operator 的效率问题 03/07 12:25
4F:→ MOONRAKER:难怪.NET也要学人家弄stringbuilder 03/07 12:26







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:BabyMother站内搜寻

TOP