주어진 텍스트 파일의 경우 모든 "\
"문자를 찾아 "\\
"으로 바꿔야합니다. 이것은 Windows 시스템이며 스크립팅 언어 옵션은 Javascript, VBScript 또는 Perl입니다.내 파일 I/O 알고리즘 개선
이 파일은 크기가 큽니다 (~ 10MB 한 장)이며 좋은 수 (~ 15,000 개)가 있습니다. 이미 다음 자바 스크립트를 제안했습니다.
function EscapeSlashes(inFilePath)
{
var readOnly = 1;
var fso = WScript.CreateObject("Scripting.FileSystemObject");
var outFile = fso.CreateTextFile(inFilePath + "escaped.js", true);
var inFile = fso.OpenTextFile(inFilePath, readOnly);
var currChar;
while(!inFile.AtEndOfStream)
{
currChar = inFile.Read(1);
//check for single backslash
if(currChar != "\\")
{
outFile.Write(currChar);
}
else
{
//write out a double backslash
outFile.Write("\\\\");
}
}
outFile.Close();
inFile.Close();
}
위의 내용이 다소 느릴 수도 있습니다. 알고리즘을 개선 할 방법이 있습니까? 한 캐릭터를 두 캐릭터로 대체 할 것이기 때문에,이 캐릭터가 제자리에서 수행 될 수 있다고 생각하지 않습니다.
문자 단위가 아닌 줄 단위로 읽는 것이 성능면에서 유리합니까?
Perl 또는 VBScript는이 경우 Javascript보다 이점이 있습니까?