Author Topic: How to search for the longest line?  (Read 2476 times)

jporkkahtc

  • Senior Community Member
  • Posts: 2620
  • Hero Points: 210
  • Text
How to search for the longest line?
« on: May 13, 2015, 01:17:22 AM »
Is there a way to find the longest line in a file?


The best I could do was to replace all characters with ".", Edit->Other->Enumerate to insert line numbers, then sort-on-selection (excluding the line numbers).


Then the last line in the buffer has the line number of the longest line from the original file.




BTW, doing a RE Search and Replace ("." for ".") takes awhile.
While doing this, Slick leaves an always-on-top tooltip window open (the red one showing the replaced text).


Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: How to search for the longest line?
« Reply #1 on: May 13, 2015, 11:30:54 AM »

Code: [Select]
_command void what_is_the_longest_line() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_READ_ONLY)
{
   int loops = 100000;
   int maxl = 0;
   int ll = 0;
   typeless po;
   save_pos(po);
   top();
   while (--loops) {
      end_line();
      if (p_col > maxl) {
         ll = p_line;
         maxl = p_col;
      }
      if (down())
         break;
   }
   if (loops <= 0) {
      _message_box("too many lines!!");
   }
   goto_line(ll);
   begin_line_text_toggle();
   push_bookmark();
   end_line();
   _message_box("Longest line is " :+ ll :+ " with " :+ maxl " characters");
   restore_pos(po);
}

jporkkahtc

  • Senior Community Member
  • Posts: 2620
  • Hero Points: 210
  • Text
Re: How to search for the longest line?
« Reply #2 on: May 13, 2015, 01:40:14 PM »
« Last Edit: February 20, 2017, 06:34:41 PM by jporkkahtc »