+ Reply to Thread
Results 1 to 6 of 6

String manipulation & modification in a TEXT file.

  1. #1
    Forum Contributor
    Join Date
    02-03-2018
    Location
    Buckinghamshire, England
    MS-Off Ver
    2010
    Posts
    130

    String manipulation & modification in a TEXT file.

    I have been coding a series of functions to open a text file, check for the existence of a whole line (each line has a parameter name and value separated by an = sign eg. GMT_StartTime=00:05). Then show the current value to the user (it reads the file in line by line to find a match of the whole line and parses out the value) and then asks if they want to modify it.

    Then it basically allows them to choose the parameter name and asks what to modify the value to.

    Then currently the code reads in the text file complete and does a replace of the existing whole line with the new line.

    I am updating 32 files currently with the same value. I.e it looks for a whole line that is common to all files and replaces the whole line in all files.

    My difficulty is that if the files have different values for the same line in different files it only finds the exact matches. This will be more common when we increment a value in each file.

    So question is. Is there a simple way of finding just the parameter name and then updating the value?

    I assume that the current way of using replace function would not be easy to modify. Would I need to read in the lines one at a time and somehow “select” the line to operate on and then do a replace on the value.

    When I first looked at this I could not see how to “select” a line (say using instr) and read it into a variable for manipulation.

    Sample data
    BanStopLoss=false
    SetStopLossForHedgedTrades=false
    CloseAllTradesOnNetProfitTrigger=false
    NetProfitTrigger=500.0
    AccountHistoryLookBackDays=3
    GMT_StartTime=08:00
    GMT_EndTime=15:00
    LotSize=0.05

    Any ideas anyone? Am I making a simple task difficult?

    Regards

    Neil

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: String manipulation & modification in a TEXT file.

    Neil

    What code do you currently have?

    Does it look for both the parameter and value?

    If all the parameters are on a separate line it should be straightforward to locate the parameter and replace whatever is after the '=' with the required value.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    02-03-2018
    Location
    Buckinghamshire, England
    MS-Off Ver
    2010
    Posts
    130

    Re: String manipulation & modification in a TEXT file.

    Currently, I can read the file in line by line and search for the name e.g. “GMT_StartTime=”, find the length of the value as an integer, then use mid (to end of line) to find the value.

    I can then read in that value and display it, etc.

    Ultimately the code below does the whole line find and replace.
    Please Login or Register  to view this content.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: String manipulation & modification in a TEXT file.

    I thought you had code that was searching for the parameter line by line?

    Something like this perhaps.
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    02-03-2018
    Location
    Buckinghamshire, England
    MS-Off Ver
    2010
    Posts
    130

    Re: String manipulation & modification in a TEXT file.

    Sorry i do have code to read in line by line and it may be that could be modified for this as I already use it to search for the string as below. I am separating the two routines here at some point

    Meanwhile i will try your code Thanks.

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    02-03-2018
    Location
    Buckinghamshire, England
    MS-Off Ver
    2010
    Posts
    130

    Re: String manipulation & modification in a TEXT file.

    Hi Code seems to work after a few tweaks to what i fed it. thank you.

    One more question but i will post separately as i think that is what i should do

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need Code Modification for Text file to Excel File
    By pvsvprasad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2016, 12:55 PM
  2. Replies: 2
    Last Post: 05-27-2016, 12:30 AM
  3. string manipulation, move letter back in the string
    By hammerjoe in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 04-22-2016, 12:49 PM
  4. [SOLVED] Slight Modification Request VBA Code - Text File to Excel
    By spiwere in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 03-22-2013, 04:39 AM
  5. Text string manipulation
    By jswgames in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 10-29-2012, 09:30 PM
  6. Text File Manipulation
    By elbarto_87 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-16-2008, 08:40 AM
  7. [SOLVED] Importing Long String - String Manipulation (INVRPT) (EDI EANCOM 96a)
    By Brian in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-09-2006, 11:45 AM

Bookmarks

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 Friendly URLs by vBSEO 3.6.0 RC 1