.
.   
NEdit.org
   .

Home
 - News - Download - Documentation - Search - FTP     
.
.
  

Togglecase

[Back]

 

To toggle the case of a character you can check whether the result of a toupper / tolower conversion is the same as before; if it is not, you have toggled the case of your character. (You really need to do this a character at a time, however.)

eg: in your .neditmacro:

define togglecase
{
s = $1
r = ""
for (i = 0, c = substring(s, i, i+1); \
     c != ""; \
     i++, c = substring(s, i, i+1))
   {
   if (toupper(c) != c)
      r = r toupper(c)
   else
      r = r tolower(c)
   }
return r
}
Now you do a little macro to, say, convert your selection:
replace_selection(togglecase(get_selection()))
or convert the next character and move on:
replace_range($cursor, $cursor+1, \
        togglecase(get_character($cursor)))
forward_character()
or to change the character behind the cursor:
replace_range($cursor, $cursor-1, \
        togglecase(get_character($cursor-1))).
[Back]

. Released on  Wed, 21 Nov 2001  by C. Denat  

  
Visit our sponsor
Check Metrolink

© NEdit.org
1999-2001
All rights reserved


.