2014-12-09 2 views
0

을 사용하여 파일에 문자열을 대체 여기 직면 문제에서 나는 데이터 아래에 포함 된 텍스트 파일이 VBScript를

mkdir language 

내가

Const ForReading = 1 
Const ForWriting = 2 

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading) 

strText = objFile.ReadAll 
objFile.Close 
strNewText = Replace(strText, "language", "english,french,spanish") 

Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForWriting) 
objFile.WriteLine strNewText 
objFile.Close 

을 얻고 텍스트 파일에 언어 문자열을 대체 내 VBScript를하다 영어, 프랑스어, 스페인어하지만 난 텍스트 파일에 출력을 원하는 방법에

mkdir english 
mkdir french 
mkdir spanish 

아래와 같이 출력 MKDIR 이

답변

0

이 너무 작동하여 빠른 회신

Const ForReading = 1 
Const ForWriting = 2 

Dim langs 
langs = Array("english","french","spanish") 

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

strText = objFile.ReadAll 
objFile.Close 
tempTxt = "" 
strNewText = "" 
For Each i in langs 
    tempTxt = "mkdir " + i + vbCrLf 
    strNewText = strNewText + tempTxt 
Next 

strNewText = Replace(strText, "mkdir language", strNewText) 

Set objFile = objFSO.OpenTextFile("Text.txt", ForWriting) 
objFile.WriteLine strNewText 
objFile.Close 
+0

감사합니다 (그러나 나는 당신의 실제에 문제가 단순화 된 샘플에 표시되지 않습니다 의심). 그것은 내 문제를 해결했다. – user3727850

0

여기이 변화를 시도 도와주세요 chieve :

Const ForReading = 1 
Const ForWriting = 2 

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForReading) 

strText = objFile.ReadAll 
objFile.Close 
Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForWriting) 

For Each strLanguage In Array("english", "french", "spanish") 
    objFile.WriteLine Replace(strText, "language", strLanguage) 
Next 

objFile.Close 
0

사용 Join 배열에서 문자열을 구축 :

물론
>> c = "mkdir " 
>> l = Split("english,french,spanish", ",") 
>> WScript.Echo c & Join(l, vbCrLf & c) 
>> 
mkdir english 
mkdir french 
mkdir spanish 

, c는 파일에서 올 수 있습니다.

은 ...

관련 문제