查找并替换问题 [英] Find and Replace question

查看:69
本文介绍了查找并替换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件,其中包含大约8到10个文本序列,我需要

替换。


我想搜索并替换所有8个每次运行时都要10个文本序列

脚本


这是我目前所拥有的。

Const ForReading = 1 < br $>
Const ForWriting = 2

strHostFile =" C:\\\ summat.dii"


设置objFSO = CreateObject(" Scripting.FileSystemObject")

设置objFile = objFSO.OpenTextFile(strHostFile,ForReading)


strText = objFile.ReadAll

objFile.Close

strNewText =替换(strText,@ EDOC,@C DocLink)

strNewText =替换(strText," @C BegDoc"," @C BegDoc#")

''等............


套装objFile = objFSO.OpenTextFile(strHostFile,ForWriting)

objFile.WriteLine strNewText


objFile.Close

唯一的文字是replac编辑最后一个strNewText

即strNewText =替换(strText,@C BegDoc,@C BegDoc#)


我是是脚本的新手所以请善待。 :)


我可以使用arrOldTexts = array(@ EDOC,@C BegDoc等等......)


对于arrOldTexts中的每个strtexts

I have a text file that contains about 8 to 10 text sequences that I need to
replace.

I want to search and replace all 8 to 10 text sequence anytime I run this
script

Here is what I have so far.
Const ForReading = 1
Const ForWriting = 2

strHostFile = "C:\summat.dii"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strHostFile, ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "@EDOC", "@C DocLink ")
strNewText = Replace(strText, "@C BegDoc", "@C BegDoc#")
''etc............

Set objFile = objFSO.OpenTextFile(strHostFile, ForWriting)
objFile.WriteLine strNewText

objFile.Close
The only text that is replaced it the last strNewText
i.e strNewText = Replace(strText, "@C BegDoc", "@C BegDoc#")

I am a novice at scripting so please be kind. :)

Could I use arrOldTexts = array("@EDOC", "@C BegDoc", etc......)

For Each strtexts in arrOldTexts


推荐答案

" Mike" YO_BEE" B" < Mi ******** @ discussion.microsoft.comschrieb
"Mike "YO_BEE" B" <Mi********@discussions.microsoft.comschrieb

设置objFile = objFSO.OpenTextFile(strHostFile,ForWriting)

objFile.WriteLine strNewText
Set objFile = objFSO.OpenTextFile(strHostFile, ForWriting)
objFile.WriteLine strNewText



看起来好老的VB6(或VBA)代码。适当的群组:mpvb。*

这个是关于VB.Net(2002-2008)

Armin

Looks like good old VB6 (or VBA) code. Appropriate group(s): m.p.vb.*
This one is about VB.Net (2002-2008)
Armin

Armin是对的,这是VB6代码,而不是VB.Net。无论如何评论内联:


迈克YO_BEE B写道:
Armin is right, this is VB6 code, not VB.Net. Comments inline anyway:

Mike "YO_BEE" B wrote:

strNewText = Replace(strText,@ EDOC,@C DocLink)
strNewText = Replace(strText, "@EDOC", "@C DocLink ")



此时strNewText包含替换; strText是

不变。

At this point strNewText contains the substitution; strText is
unchanged.


strNewText = Replace(strText,@C BegDoc,@C BegDoc#)
strNewText = Replace(strText, "@C BegDoc", "@C BegDoc#")



因此该行应为

strNewText = Replace(strNewText,@C BegDoc,@C BegDoc# )

Therefore that line should be
strNewText = Replace(strNewText , "@C BegDoc", "@C BegDoc#")


>

我可以使用arrOldTexts = array(@ EDOC,@C BegDoc等等。 ....)
>
Could I use arrOldTexts = array("@EDOC", "@C BegDoc", etc......)



你可以使用数组,但它不支持For Each;你需要一个

指数。首先,让它像上面的单独行一样工作;然后你

可以看看使用数组。

You could use an array, but it won''t support For Each; you''ll need an
index. First, though, get it working as individual lines as above; then you
can look at using an array.


你能提供更多帮助吗?


所以当我做strText = objFile.ReadAll

此时是否已编入索引?

我从哪里开始?


这个脚本将是* .VBS


每次都会运行相同的程序。

Steve Gerrard写道:
Can you give some more assistance?

So when I do the strText = objFile.ReadAll
Is this indexed at this point?
Where do I go from here?

This script will be a *.VBS

It will run the same procedure every time.
"Steve Gerrard" wrote:

Armin是对的,这是VB6代码,而不是VB.Net。无论如何评论内联:


迈克YO_BEE B写道:
Armin is right, this is VB6 code, not VB.Net. Comments inline anyway:

Mike "YO_BEE" B wrote:

strNewText = Replace(strText,@ EDOC,@C DocLink)
strNewText = Replace(strText, "@EDOC", "@C DocLink ")



此时strNewText包含替换; strText是

不变。


At this point strNewText contains the substitution; strText is
unchanged.


strNewText = Replace(strText,@C BegDoc,@C BegDoc#)
strNewText = Replace(strText, "@C BegDoc", "@C BegDoc#")



因此该行应为

strNewText = Replace(strNewText,@C BegDoc,@C BegDoc# )


Therefore that line should be
strNewText = Replace(strNewText , "@C BegDoc", "@C BegDoc#")



我可以使用arrOldTexts = array(" @ @ EDOC"," @C BegDoc",etc ......)

Could I use arrOldTexts = array("@EDOC", "@C BegDoc", etc......)



您可以使用数组,但它不支持For Each;你需要一个

指数。首先,让它像上面的单独行一样工作;那么你

可以看一下使用数组。


You could use an array, but it won''t support For Each; you''ll need an
index. First, though, get it working as individual lines as above; then you
can look at using an array.


这篇关于查找并替换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆