November 25, 2010 at 1:13 am
need help with vbscript code to read specific number of characters from a text file and save them to another file
For example : read all the characters from 10th character to the 20th character and write these characters to another text file
I know its simple but i cant seem to figure it out.
code needs to be in vbscript not vb6 or .net
Can anybody help?
Thanks
November 25, 2010 at 4:30 am
is that characters 10 thru 20 of the whole file, or 10 thru 20 for each row/line in the file? so if the file has 120 lines, you need a table with that many results?
dim fsoobj ' As FileSystemObject
dim strobj ' As FileStream
dim FileContents ' As String
dim CurrentRow ' As String
Set fsoobj = CreateObject("Scripting.FileSystemObject")
'1 = ForReading, 2 = ForWriting, 8 = ForAppending
Set strobj = fsoobj.OpenTextFile("c:\Data\toys.txt",1)
FileContents = strobj.ReadAll
strobj.Close
'get the string
CurrentRow = mid(FileContents,10,10)
'now write the file True =Create if not exists
Set strobj = fsoobj.OpenTextFile("c:\Data\anewfile.txt",2,True)
strobj.WriteLine CurrentRow
strobj.Close
Lowell
November 25, 2010 at 4:57 am
Thanks dude
November 25, 2010 at 9:16 pm
Lowell (11/25/2010)
is that characters 10 thru 20 of the whole file, or 10 thru 20 for each row/line in the file? so if the file has 120 lines, you need a table with that many results?
dim fsoobj ' As FileSystemObject
dim strobj ' As FileStream
dim FileContents ' As String
dim CurrentRow ' As String
Set fsoobj = CreateObject("Scripting.FileSystemObject")
'1 = ForReading, 2 = ForWriting, 8 = ForAppending
Set strobj = fsoobj.OpenTextFile("c:\Data\toys.txt",1)
FileContents = strobj.ReadAll
strobj.Close
'get the string
CurrentRow = mid(FileContents,10,10)
'now write the file True =Create if not exists
Set strobj = fsoobj.OpenTextFile("c:\Data\anewfile.txt",2,True)
strobj.WriteLine CurrentRow
strobj.Close
Hi Lowell,
Am I reading that correctly? Does it read the entire file first? I'm asking because if you need to read the kind of files I typically have to work with (more than 10GB is typical), I beleive the system is going to become a little starved for memory. Wouldn't a read-1, write-1 methodology be better?
--Jeff Moden
Change is inevitable... Change for the better is not.
December 7, 2010 at 1:12 pm
The problem is that the parameter prompt still pops. I am beginning to wonder if this does not work in Access 2003? I have seen severla post with people asking the same question with no good answer. Maybe a Microsoft developer would know? Thanks!
Online shopping at Chinabuye for dropship electronics[/url] Service
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy