SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Jun 2006
    Posts
    20
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Opening a notepad file and editing text

    Hi

    I have some txt files, which having some text in that. My requirement is:

    1. Open the first file and extract from 6 to 18 characters from the first line(always same line)and replace it with some other text.
    2. do the same thing for all the txt files
    3. But the source string will be different to different txt file.

    Where iam stuck up:

    If I open the file in write mode, it is clearing the entire text.
    If I open the file in Append mode, it will append at end of the file.

    My approach:

    1. Open the file(not clear in which mode to open)
    2. file_getline()
    3. take the substring(6,18)
    4. switch(string)
    case 1:
    case 2:
    ------
    5. Dont know how to replace a string with other

    can you please suggest me in this??

    Thanks
    Phani

  2. #2
    Senior Member
    Join Date
    May 2003
    Location
    Austria
    Posts
    1,480
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Opening a notepad file and editing text

    There are 2 issues for which you need a solution:
    1. How to replace a part of a string?
    2. How to modify lines in a file?

    ad 1. A string-replacement-function will consist of the functions index (or match), length and substr. I guess if you search through this forum, this function may have been posted a longer time ago.

    ad 2. There is no function for reading & writing a file at once. You will have to read the file first and then write (the modified file) again. You can do this by storing the lines of the file in an array (if the file is not too big), or you can write a 2nd file while reading the first file line by line, and then replace the first file by the 2nd file (e.g. by using dos_system and some DOS-commands).

    Regards,
    Juergen

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.54%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 01:45 PM.

Copyright BetaSoft Inc.