Capitalisation command or macro ?

AVKuznetsov kuzn at htsc.mephi.ru
Tue May 26 08:39:15 CEST 2009


On Tue, 26 May 2009 10:25:40 +1000
Greg Edwards <gedwards2 at gmail.com> wrote:

> Nedit comrades,
> I have to capitalise a pile of text  - massive list of book titles, eg
> "night of the living dead" goes to 'Night Of The Living Dead". I was sure
> nedit had this built in but just can't find it. Help appreciated.
> 
> Cheers,
> Greg E
> 

Hi Greg!

Try following macro.

define capitalize_region {
   if( $selection_start != -1 ) {
      start = $selection_start
      end = $selection_end
   } else {
      start = 0
      end = $text_length
   }
   string = get_range(start, end)
   for(position=0; 1; position = $search_end) {
      position = search_string(string, "(?<=\\L|^)\\l+", position, "regex")
      if(position < 0)
         break
      char = toupper(substring(string, position, position +1))
      string = replace_substring(string ,position, position +1, char)
   }
   replace_range(start, end, string)
}

You can tune the macro and replace \\L to \\s to capitalize
only words separated by spaces. 

Cheers,
Alexey Kuznetsov


More information about the Discuss mailing list