我試圖插入一個以word標題開頭的字符串,如title: New string to be inserted
到具有以下格式的文件中。頂部有一堆文本,每行以title:開頭,底部有一堆文本。vbscript按字母順序插入一行
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行,然後你也說我的標題在那裏複製?我不明白。請詳細說明。 – Pavan 2010-10-01 15:09:41