text replaceing via *.bat
|
Original Message
|
Name: renis
Date: July 2, 2007 at 23:27:29 Pacific
Subject: text replaceing via *.batOS: XPCPU/Ram: 1GBModel/Manufacturer: pentium 4 |
Comment: I need to change/replace a word in a row in batch file. for example "localhost" to "AAA". Supose there are no diference to the same in *.txt however can someone help me? thanks!
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: renis
Date: July 3, 2007 at 00:42:35 Pacific
Subject: text replaceing via *.bat |
Reply: (edit)I found one way to do this but there is one litte problem again. I don`t want to change all "Jim" to "James" but in one row only. who can help me with this .vbs script? thanks! 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, "Jim ", "James ") Set objFile = objFSO.OpenTextFile("C:\Scripts\Text.txt", ForWriting) objFile.WriteLine strNewText objFile.Close
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: ghostdog
Date: July 3, 2007 at 02:22:17 Pacific
Subject: text replaceing via *.bat |
Reply: (edit)the replace function has an optional "start" and "count" argument. you can use that. Put count = 1, eg [code] Replace(strText, "Jim ", "James ",1,1) [/code] it will replace just 1 instance of Jim.
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: ghostdog
Date: July 4, 2007 at 01:38:58 Pacific
Subject: text replaceing via *.bat |
Reply: (edit)then you can switch from using ReadAll, to Readline, ie go through the files line by line. That way you can determine which lines you want to stop replacing. this is just one suggestion.
Report Offensive Follow Up For Removal
|
Use following form to reply to current message: