Announcement

Collapse
No announcement yet.

Find text from end ( Text file ) !?

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

  • Find text from end ( Text file ) !?

    Hello, I need solution to search text from end to beginning in text file ( not from beginning to end ) using String.Find ?!

    I have a big (mb) log file and are important to me last lines of text file ( goes much faster searches )

    Regards

  • #2
    Code:
    TextFileStr = TextFile.ReadToString(filename);
    
    FindPos = String.ReverseFind(TextFileStr, searchparameter, startposition, casesensitive);
    
    if FindPos ~= -1 then
            Dialog.Message("Found", "Found searchparameter at " .. FindPos);
    end
    Does that help?

    Comment


    • #3
      No it did not help and this is how it looks

      local test = assert(io.open("C:\\test.txt", "rb"))
      local testdata = test:read("*all")

      startposition = 1;
      searchparameter = "test";

      TextFileStr = TextFile.ReadToString(testdata);

      FindPos = String.ReverseFind(TextFileStr, searchparameter, startposition, casesensitive);

      if FindPos ~= -1 then
      Dialog.Message("Found", "Found searchparameter at " .. FindPos);
      end

      Comment


      • #4
        If you are searching for a word backwards then you have to first make the word you are searching for backwards.

        If its the last line you are after, or the last lines, it might be easier to split the string to a table by line and work from there.

        Comment


        • #5
          I need searching for a word backwards (ThisText) from text file !

          Example:
          ThisText
          word 12234
          word link
          word aaaaaaa
          word ThisText
          dsdsd ofdofdkfd
          How do I search starts from the end of ?

          Comment


          • #6
            Any help ?

            Comment


            • #7
              Look up String.ReverseFind in manual.
              Bas Groothedde
              Imagine Programming :: Blog

              AMS8 Plugins
              IMXLH Compiler

              Comment


              • #8
                Thanks, working !!!

                Comment


                • #9
                  Originally posted by saricnet View Post
                  Thanks, working !!!
                  Why don't read users' posts?

                  Originally posted by HobbsyJr View Post
                  Code:
                  TextFileStr = TextFile.ReadToString(filename);
                  
                  FindPos = [B]String.ReverseFind[/B](TextFileStr, searchparameter, startposition, casesensitive);
                  
                  if FindPos ~= -1 then
                          Dialog.Message("Found", "Found searchparameter at " .. FindPos);
                  end
                  We are slowly invading your planet to teach lazy humans to read the user manual.
                  But don't be scared: we are here to help.

                  Comment


                  • #10
                    Cheers Cyber

                    Comment

                    Working...
                    X