Announcement

Collapse
No announcement yet.

Search substring in text file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Search substring in text file

    hello,
    I would like to search a substring in the content of a log file.
    as the log file can be a long file, more than 2000 lines, I think I cannot use "TextFile.ReadToString" but probably "TextFile.ReadToTable".

    But despite several tests, I didn't succes to find my string .
    can someone help me or give tips.

    thanks

    --JL

  • #2
    maybe this help

    myTable = TextFile.ReadToTable("C:\\log.txt");
    old_string = "this is my string";
    new_string = "this is new my string";
    tmax=Table.Count(myTable);

    for loop = 1, tmax do
    sFind = String.Find(myTable[loop], old_string, 1, true);
    if sFind ~= -1 then
    Position = loop -1
    Table.Insert(myTable, Position, new_string);
    break;
    end
    end
    TextFile.WriteFromTable(C:\\log.txt", myTable, false);

    Comment


    • #3
      Thanks Syahendra,
      I am going to test using a loop as suggested. ​​​​​​

      --JL

      Comment

      Working...
      X