【发布时间】:2010-10-01 14:12:36
【问题描述】:
我正在尝试插入一个以标题开头的字符串,如title: New string to be inserted
到具有以下格式的文件中。顶部的一堆文本,每行以单词 title: 开头的一行,底部的一堆文本。
Some content here at the top
And more content
and the titles will begin next
title: Basic String
title: How does it evaluate strings
title: Identify code links
title: Translating vbscript to string
some content at the bottom
and more content at the bottom
问题是我更喜欢插入那个新字符串title: New string to be inserted,以便它在标题块中按字母顺序组织,以便更容易维护这个文件。我怎样才能用 vbscript 做到这一点。几个小时前我发现了它,并认为它是我正在尝试做的事情的一个很好的选择,但还不是很擅长,所以任何帮助都会很棒
如何循环遍历所有行 文件,将每一行复制到一个新的 文件,直到我找到一个标题 在我的标题后按字母顺序添加我的 那个地方的新文件的标题, 然后将文件的其余部分复制到 新建文件并关闭。
因为我vbscript语法不好,只能想到一个伪算法,
Loop to read through all lines
If the line does not start with the word title:, copy it as is into the new file
If the line starts with the word title, remove the `title:` sub-string, then check if it is alphabetically before or after my title
If before my title, copy it into the new file
If after my title, then copy my title there, and copy all rest of the file as is, and EXIT
End loop
【问题讨论】:
-
在你的循环中,前两行对我来说很有意义。但是,如果在循环中第三行的我的标题之前,您是什么意思?如果在我的标题之后,在循环中的第 4 行,然后你还说在那里复制我的标题,你是什么意思?我不明白。请详细说明。
标签: windows vbscript batch-file