Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2007
    Posts
    32

    Editin multiple lines in text file

    Is it possible to edit more than one string within a text file using the TextFile.WriteToString command? I have numerous text files that I need to edit more than just one word within its contents. I've looked into writing the contents of the text file to a table, but it seems like a long and involved process just to edit multiple lines. Thanks.

  2. #2
    Join Date
    Sep 2007
    Posts
    32
    To clarify, if I wanted to replace more than one string within a text file, could I achieve this by the following:

    Code:
    String.Replace(fileContents, "this", "that", true);
    String.Replace(fileContents, "here", "there", true);
    Where I am attempting to replace all occurrences of "this" with "that" and "here" with "there" (just as examples of course). Also, then I would need to store both of these changes into a variable that I would need to write back to the directory. If I am either on the right or wrong track, please let me know. Thanks.

  3. #3
    Join Date
    Jun 2005
    Posts
    470
    this is surely possible, you need to read the file to some variable, and then sequentially perform all the desired replacements to that variable. Finally, write the modified variable to a text file(same or new). For example

    Code:
    myTxt = TextFile.ReadToString("C:\\test.txt");
    myTxt = String.Replace(myTxt, "this", "that", true);
    myTxt = String.Replace(myTxt, "here", "there", true);
    myTxt = String.Replace(myTxt, "something", "anotherthing", true);
    TextFile.WriteFromString("C:\\test_1.txt", myTxt, false);

  4. #4
    Join Date
    Jan 2001
    Location
    Anderson Island, WA, USA
    Posts
    2,862
    Be sure to pay attention to what you're changing! it is not a regex replacement....

    i you replace "at" with "@" in "what is that boy standing at attention for?" you will get
    "wh@ is th@ boy standing @ @tention for? "


    (Click here to contact me)
    Providing Independent Professional Consulting Services for
    IndigoRose products, World Wide.
    Located in -8:00 (-7:00 DST) GMT Timezone (Western United States)

Similar Threads

  1. Formating a text or htm file HELP !!!!
    By lance in forum AutoPlay Media Studio 5.0
    Replies: 1
    Last Post: 08-30-2005, 11:42 AM
  2. Flash with text file
    By whatever in forum AutoPlay Media Studio 5.0
    Replies: 3
    Last Post: 06-14-2005, 12:49 PM
  3. Example: Loading Paragraph Text Using a Timer
    By Jonas DK in forum AutoPlay Media Studio 5.0 Examples
    Replies: 7
    Last Post: 11-25-2004, 05:10 PM
  4. Default text in edit field - Multiple edit screen
    By Romahe in forum Setup Factory 6.0
    Replies: 1
    Last Post: 12-18-2001, 01:01 PM
  5. Can search allow manual browse even if file is found?
    By RichardShaw in forum Setup Factory 5.0
    Replies: 2
    Last Post: 08-28-2000, 06:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts