Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently April 22nd, 2025, 12:23 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Using Write, WriteLine
PostPosted: March 21st, 2005, 3:21 pm 
Offline

Joined: February 4th, 2005, 5:59 am
Posts: 81
Location: Bristol, UK
Hi chaps,

Can someone help me with Write?

I have a text file which has 4 lines:

ONE=Apples
TWO=Cucumbers
THREE=
FOUR=


I want to find and append to line 3 so that it reads:

ONE=Apples
TWO=Cucumbers
THREE=A lone moose
FOUR=


I have script like this:

Code:
function updatethings()
{
var filestr = "C:\\things.txt"
var myfile = OpenFile(filestr)

if (myfile == null)
   {
   Debug.trace("Unable to open file" + filestr)
   return;
   }
else
   {
   Debug.trace(filestr + " is open" + "\n")
   }
   
while (myfile.EndOfFile() == false)
{
   var myrec = myfile.ReadLine();
   Debug.trace("Reading record: " + myrec + "\n")
   if (String.contains(myrec,"THREE="))
      {
      Debug.trace("Found THREE!" + "\n")
      myfile.Write("A lone moose")//is appending to end of file
      //myfile.WriteLine("A lone moose")//is appending to end of file
      Debug.trace("Updated: " + myrec + "\n")
      }
   else
      {
      Debug.trace("Not THREE" + "\n")
      }
   wait();
   }
}


Both Write and WriteLine are appending to the file.

How do I append to the line?

I'd appreciate any pointers...

Thanks

Melanie :D

_________________
Win XP, 3.4 HT P4, 1GB ram, Nvidia Geforce 6610 XL, DirectX 9.0c
Opus Pro 04 XE version 4.50
Opus 2.81


Top
 Profile  
 
 Post subject:
PostPosted: March 21st, 2005, 4:41 pm 
Offline

Joined: October 25th, 2004, 12:27 pm
Posts: 526
Location: Digital Workshop
Hi,

Thank you for your enquiry.

The main problem is that your OpenFile() action does not contain the overwrite parameter, so it is not possible to insert values into the existing text, and all information written to the file will be appended to the end. However, if you use the overwrite parameter in your current OpenFile() action, the entire contents of the file will be deleted before you can check each line.

One solution is to use a normal OpenFile() action to read from the file and store each of the lines of text into an array. Whilst the lines are being stored to the array, you can check for any particular strings (such as 'THREE=') and append information to the current index of the array.

Once all of the lines from the text file have been stored into the array and any matching search values have been modified to include the appended text, you can then close the original file and reopen it with an OpenFile() action set to Overwrite. This will clear the contents of the text file, but you can now use WriteLine() actions to write each index of the array back to the file.

I have attached a sample publication which demonstrates this.

Kind regards,


You do not have the required permissions to view the files attached to this post.

_________________
Robin Garrett
Digital Workshop Technical Support


Top
 Profile Visit website  
 
 Post subject: Write file with quotation marks
PostPosted: March 21st, 2005, 6:17 pm 
Offline

Joined: February 4th, 2005, 5:59 am
Posts: 81
Location: Bristol, UK
Thanks so much, Robin, that's great :D

Just one more question (but a crucial one, wish I'd thought of it earlier) - how can I embed quotation marks so that I can produce (using same example):

ONE=Apples
TWO=Cukes
THREE="A lone moose"
FOUR=

Can anyone help? :?:

Thanks again,

Melanie :D

_________________
Win XP, 3.4 HT P4, 1GB ram, Nvidia Geforce 6610 XL, DirectX 9.0c
Opus Pro 04 XE version 4.50
Opus 2.81


Top
 Profile  
 
 Post subject: escape it
PostPosted: March 21st, 2005, 7:54 pm 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
Hi Melanie

You have to escape quote marks with a forward slash so Opus knows the quotemarks are part of a string and not the start or finish of one.

THREE="\"A lone moose\""

cheers
Paul


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group