Jump to content

Recommended Posts

Posted

say i have a text file like below (but with multiple lines) is there anyway i can read in a line replace most of it but keep the end say. So say i have a script that fills in certain bits but i want to be able to manually add stuff to it it wont wipe it out

 

example

 

pc01,hp compaq 610,4gb,120gb,80gb,serialno,12-12-2010,3,12-12-2013

 

so whats in red is readded by script at intervals the black text is manually added by me at some point

Posted (edited)
If it's just just the dates you want to keep hold of you could use a regular expression or if it's the last two entries just look for the position of the comma and chop it there. Edited by ChrisH
Posted
If it's just just the dates you want to keep hold of you could use a regular expression or if it's the last two entries just look for the position of the comma and chop it there.

 

ok i think i get the idea if no the execution lol

 

so basically get it to count ,s and copy anything after , 6 to a new variable and then just write it back?

Posted
Yes that would be one way of doing it using the right or left function once you get the position of the relevant comma. It would all depend on if the number of entries per line were the same eg there will only be two dates etc. Using a regular expression to pick out the dates would probably be the proper way to do it though.
Posted
Yes that would be one way of doing it using the right or left function once you get the position of the relevant comma. It would all depend on if the number of entries per line were the same eg there will only be two dates etc. Using a regular expression to pick out the dates would probably be the proper way to do it though.

 

ok but thats a new one one me looks like some more googlefu is needed. The entries per line should always be identical as the way the content is generated even if it returns a null value it will insert the , as a field separator

Posted

If it is the same number of entries in the same order then you could simply use the split function which will use the comma as a qualifier and put the line into an array so

 

pc01,hp compaq 610,4gb,120gb,80gb,serialno,12-12-2010,3,12-12-2013

 

fed to the split function would end up like

 

myArray = Split(strLineFromFile,",")

Which would populate the array like below :

myArray(0) = "pc01"
myArray(1) = "hp compaq 610"
myArray(2) = "4gb"
myArray(3) = "120gb"
myArray(4) = "80gb"
myArray(5) = "serialno"
myArray(6) = "12-12-2010"
myArray(7) = "12-12-2013"

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...