Author Topic: count characters  (Read 3744 times)

rod_gomz

  • Community Member
  • Posts: 80
  • Hero Points: 1
count characters
« on: March 22, 2010, 08:07:37 PM »
Is there a built in function or macro or something that counts charactes in a highligted block? The current display shows: "19+" lines. I would like a character count.

I know in unix wc works so something similar would be nice.

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: count characters
« Reply #1 on: March 22, 2010, 09:05:33 PM »
Maybe take it as starting point for your own macro or just use it...

Code: [Select]
#pragma option(strict,on)
#include 'slick.sh'

_command void count_selchars( boolean deselect = true )  name_info (','VSARG2_MARK|VSARG2_TEXT_BOX|VSARG2_READ_ONLY)
{
   if ( _isnull_selection() )
   {
      message ("Nothing selected !");
      return;
   }
   int cnt = 0;
   _str seltext;
   filter_init();

   while ( filter_get_string(seltext) == 0 )
      cnt += length( seltext );

   filter_restore_pos();
   if ( deselect ) _deselect();
   message("selected " cnt " chars");
}

There are also other methods possible e.g. duplicate the selection to a temp buffer and get it's size or use the temp buffer for further operations.
Have fun,
HS2

rod_gomz

  • Community Member
  • Posts: 80
  • Hero Points: 1
Re: count characters
« Reply #2 on: March 22, 2010, 09:07:15 PM »
Cool thanks.

rod_gomz

  • Community Member
  • Posts: 80
  • Hero Points: 1
Re: count characters
« Reply #3 on: March 22, 2010, 09:11:30 PM »
This worked right away.

I have some DDL in a PL/SQL block that was bigger than 32k. So I had to delete some whitespace to bring it down, though it would be nice to know how much do I need to delete.