string replace...
Moderators: JRL, Dorian (MJT support)
-
- Pro Scripter
- Posts: 58
- Joined: Thu Oct 16, 2003 12:53 am
string replace...
I have made a text file of the structure of a CD - but I need to clean the file by removing the leading three characters containing the drive name - "D:\" how do I remove the firs three characters of each line regardless of what those characters are...any links...???
Last edited by BlackWisdom on Tue Dec 20, 2005 3:28 am, edited 1 time in total.
-
- Pro Scripter
- Posts: 58
- Joined: Thu Oct 16, 2003 12:53 am
sorry..
hi me_again - Im sorry - I resovled the previosu post and re-edited the topic but I guess you must have read it before I changed it ...
-
- Pro Scripter
- Posts: 58
- Joined: Thu Oct 16, 2003 12:53 am
thanks Me_Again
and no the question wont get changed again
- but you were right there was a debug version in the MJT folder:
Iwill give you suggestioin a try and get back with you

- but you were right there was a debug version in the MJT folder:
Iwill give you suggestioin a try and get back with you
-
- Pro Scripter
- Posts: 58
- Joined: Thu Oct 16, 2003 12:53 am
input past end of file...
hey guys I wrote this VBScript :
VBSTART
Set objFSO = CreateObject("Scripting.FileSystemObject")
arrFiles = Array("BackTemp\D_results.txt")
For Each strFile In arrFiles
Set objFile = objFSO.OpenTextFile(strFile, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "D:\", "")
Set objFile = objFSO.OpenTextFile(strFile, ForWriting)
objFile.WriteLine strNewText
objFile.Close
Next
VBEND
I attempts to prcess the file - but then I get this error:
---------------------------
Macro Scheduler
---------------------------
Microsoft VBScript runtime error :62
Input past end of file
Line 74, Column 2
---------------------------
OK
---------------------------
I cant use MSChed EOF code because VBScript sees it as a syntax error - any ideas...???
VBSTART
Set objFSO = CreateObject("Scripting.FileSystemObject")
arrFiles = Array("BackTemp\D_results.txt")
For Each strFile In arrFiles
Set objFile = objFSO.OpenTextFile(strFile, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "D:\", "")
Set objFile = objFSO.OpenTextFile(strFile, ForWriting)
objFile.WriteLine strNewText
objFile.Close
Next
VBEND
I attempts to prcess the file - but then I get this error:
---------------------------
Macro Scheduler
---------------------------
Microsoft VBScript runtime error :62
Input past end of file
Line 74, Column 2
---------------------------
OK
---------------------------
I cant use MSChed EOF code because VBScript sees it as a syntax error - any ideas...???
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
How about a simple VB Replace function in the middle of Macro Scheduler sript?
Actually the Replace line does not require the result to have a new name.
VBEval>Replace("%string%","D:\",""),string is also acceptable.
Code: Select all
//Next two lines only needed once at top of script
VBSTART
VBEND
//You could put the next VBEVAL line in a loop and parse every %string%.
VBEval>Replace("%string%","D:\",""),newstringname
//==========================================
VBEval>Replace("%string%","D:\",""),string is also acceptable.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
Search and replace isn't going to do it because as I read the spec
Let>CF_OVERWRITE=1
DeleteFile>c:\temp\test2.txt
Let>k=1
Label>start
ReadLn>c:\temp\test.txt,k,line
If>line=##EOF##,finish
Length>line,len
Sub>len,3
MidStr>line,4,%len%,nuline
WriteLn>c:\temp\test2.txt,result,nuline
Let>k=k+1
Goto>start
Label>finish
CopyFile>c:\temp\test2.txt,c:\temp\test.txt
it may be some other drive letter instead of D. So, as I suggested above:how do I remove the firs three characters of each line regardless of what those characters are
Let>CF_OVERWRITE=1
DeleteFile>c:\temp\test2.txt
Let>k=1
Label>start
ReadLn>c:\temp\test.txt,k,line
If>line=##EOF##,finish
Length>line,len
Sub>len,3
MidStr>line,4,%len%,nuline
WriteLn>c:\temp\test2.txt,result,nuline
Let>k=k+1
Goto>start
Label>finish
CopyFile>c:\temp\test2.txt,c:\temp\test.txt
If you're looking for a specific string to replace, rather than resorting to VB script, why not use the Macro Scheduler command "StringReplace".
ReadFile>%TEMP_DIR%\D_results.txt,file
StringReplace>%file%,D:\,,newfile
WriteLn>%TEMP_DIR%No_D_results.txt,wresult,%newfile%
If looking for any drive letter as Me_again has pointed out, one "midstr" could be added. Assuming the first line is a valid path beginning with a drive letter (as I think all of these examples would require), use midstr to identify the first three characters of the first line then replace all occurences of those three characters with "nul".
ReadFile>%TEMP_DIR%\D_results.txt,file
Midstr>%file%,1,3,drive
StringReplace>%file%,%drive%,,newfile
WriteLn>%TEMP_DIR%No_D_results.txt,wresult,%newfile%
Later,
Dick
ReadFile>%TEMP_DIR%\D_results.txt,file
StringReplace>%file%,D:\,,newfile
WriteLn>%TEMP_DIR%No_D_results.txt,wresult,%newfile%
If looking for any drive letter as Me_again has pointed out, one "midstr" could be added. Assuming the first line is a valid path beginning with a drive letter (as I think all of these examples would require), use midstr to identify the first three characters of the first line then replace all occurences of those three characters with "nul".
ReadFile>%TEMP_DIR%\D_results.txt,file
Midstr>%file%,1,3,drive
StringReplace>%file%,%drive%,,newfile
WriteLn>%TEMP_DIR%No_D_results.txt,wresult,%newfile%
Later,
Dick
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Even shorter:Captive wrote:Effectively the same thing, but cut down to 1 line of VB...
VBEval>Right("%MyString%",Len("%MyString%") - 3),MyResult
(You could use MyString instead of MyResult too.)
Because we're using VBScript, don't forget to put
VBSTART
VBEND
at the top of your script if it's not already there.
Let>MyString={copy(%MyString%,4,length(%MyString%))}
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?