加快vbs中文本文件的循环速度

发布于 2024-11-27 03:15:33 字数 1280 浏览 3 评论 0原文

下午好,

我的代码有问题,我循环遍历文本文件。该文本文件大约有 10,000 行,因此我想出了使用 instr 搜索函数来查找行号,方法是查找出现“测试名称”的字符号,然后使用 mid 函数并向左计数来查找行号。

例如。

000004###24503###开设帐户Web ISA single###2#########请输入您的第一个姓名.###假##########先生############callie###################### #################################################### #################### #################################################### #################################################### #################################### #################################################### ################################################666 ###Imagenericpassword###Ops##### #################################################### #################################################### ##############################现金ISA 2009 / 2010################################################## #################################################### ################ #################################################### #################################################### ##################

因此,在本例中,它会找到“Open Account Web ISA single”并向左计数以找到 000004。因此,这可以节省我循环遍历 10,000 行的时间。

所以接下来我使用 ### 作为分隔符将这一行分割成一个数组,这会导致很多空的“列”,因为当我连接 Excel 中的数据时它们是空的。这使得我总共有大约 247 列。我的问题是我不想真正循环 247 列,因为其中很多包含......好吧什么也没有。有没有更快的方法让我做到这一点?

我以前用过excel,但是速度太慢了。

Good afternoon,

I have a problem with my code where im looping through a textfile. The textfile has approx 10,000 lines so I came up with using the instr search function to find the line number by finding the character number in which the "test name" appears and then using the mid function and counting left to find the line number.

eg.

000004###24503###Open Account Web ISA single###2#########Please enter your first name.###False#########Mr############callie####################################################################################################################################################################################################################################################################################################################################666###Imagenericpassword###Ops#######################################################################################################################################Cash ISA 2009 / 2010##########################################################################################################################################################################################################################################

So in this case it finds "Open Account Web ISA single" and counts left to find 000004. So this saves me looping through 10,000 lines.

So next I split this line into an array using ### as a delimeter, this results in lots of empty "columns" since they were empty when i concatinated the data from excel. This leaves me with a total of around 247 columns. My issue is I dont want to really loop through 247 columns since lots of them contain...well nothing. Is there a quicker way for me to do this?

I used to use excel but its far too slow.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风向决定发型 2024-12-04 03:15:33

您可以删除空列:

Set re = New RegExp
re.Pattern = "(###){2,}"
re.Global = True
withoutEmptyCols=re.Replace(input,"###")

这是您的示例的结果:

000004###24503###开设帐户 Web ISA single###2###请输入您的名字。###False###Mr###callie###666###Imagenericpassword# ##Ops####Cash ISA 2009 / 2010###

You can remove the empty columns:

Set re = New RegExp
re.Pattern = "(###){2,}"
re.Global = True
withoutEmptyCols=re.Replace(input,"###")

This is the result for your example:

000004###24503###Open Account Web ISA single###2###Please enter your first name.###False###Mr###callie###666###Imagenericpassword###Ops###Cash ISA 2009 / 2010###

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文