Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 3 of 3

Thread: For loop

  1. #1
    Join Date
    Dec 2003
    Location
    The Netherlands
    Posts
    475

    For loop

    Hello everybody

    I have a string from which i want to filter some words. This is the code i use;
    ------------------------------------------------------------------------
    strString = TextFile.ReadToString("Data\\2.txt");

    tblFilters = {};
    tblFilters[1] = "item1";
    tblFilters[2] = "item2";
    tblFilters[3] = "itme3";

    resRepString = String.Replace(strString, tblFilters[1], "", false);
    resRepString = String.Replace(resRepString, tblFilters[2], "", false);
    resRepString = String.Replace(resRepString, tblFilters[3], "", false);

    TextFile.WriteFromString("Data\\3.txt", resRepString, false);
    ------------------------------------------------------------------------
    As the filter list grows so will grow the String.Replace procedure.
    My question is this; how can i use the for loop here in order to make the script more flexible?

    Any idea is appreciated.

    Thank you

    Sside

  2. #2
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    Code:
    strString = TextFile.ReadToString("Data\\2.txt");
    
    tblFilters = {};
    tblFilters[1] = "item1";
    tblFilters[2] = "item2";
    tblFilters[3] = "itme3";
    
    for n, Table.Count(tblFilters) do
         strString = String.Replace(strString, tblFilters[n], "", false);
    end
    
    TextFile.WriteFromString("Data\\3.txt", strString, false);

  3. #3
    Join Date
    Dec 2003
    Location
    The Netherlands
    Posts
    475
    Thanks a lot Worm, you've been very helpful.

    Sside

Posting Permissions

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