Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Convert text - uppercase, lowercase, capitalized or inverted


  • Please log in to reply
33 replies to this topic
parikshith
  • Members
  • 1 posts
  • Last active: Aug 24 2014 02:02 PM
  • Joined: 24 Aug 2014

One of the things I like best about NoteTab is that it has a bunch of features for converting the case of text. If you highlight a string of text, you can instantly convert it to any one of lower case, upper case, capitalized case, sentence case or inverted case. Once you have highlighted the case, the following codes will convert it as follows:

CTL+L - convert to lowercase
CTL+U - convert to uppercase
CTL+K - invert the case (e.g. "The Big Dog" becomes "tHE bIG dOG")
SHIFT+CTL+K - convert to capitalized (e.g. "the big dog" becomes "The Big Dog")
SHIFT+CTL+U - convert to sentence case

Unfortunately, anytime I am creating text but not using NoteTab, (for example, at the present time, when I am preparing this post to write to this message board - I'm using some editor that is built into this particular message board) or I'm using a word processor or another editor, I find myself often needing to use these features. But they aren't available anywhere other than the editor NoteTab and I have to either convert the text manually or copy it into NoteTab, convert it there and then copy it back.

So, I wrote a similar set of features using AutoHotkey and they can be used in any editor or word processor. The way they work is that you copy the text into the clipboard, then press one of the hotkeys to convert it, then you can position the cursor anywhere you like and then send the text to that position. There is no real reason why I wrote the code this way. I suppose I could have equally well written it to perform in the same way as the code in NoteTab. The advantage to this method is that you don't have to convert the text in place. Once you copy it into the clipboard, you can move the cursor anywhere and produce the text at that point.

I find it so amazing that the original author of NoteTab probably spent many hours to write and debug this code, whereas it only took me an hour to write it using AutoHotkey. Here are the hotkeys. It's interesting that they all are pretty straightforward except for "invert text" which is a little complex:
 

^u::                                                                 ; Convert text to upper
 StringUpper Clipboard, Clipboard
 Send %Clipboard%
RETURN

^l::                                                                 ; Convert text to lower
 StringLower Clipboard, Clipboard
 Send %Clipboard%
RETURN

+^k::                                                                ; Convert text to capitalized
 StringUpper Clipboard, Clipboard, T
 Send %Clipboard%
RETURN

^k::                                                                 ; Convert text to inverted
 Lab_Invert_Char_Out:= ""
 Loop % Strlen(Clipboard) {
    Lab_Invert_Char:= Substr(Clipboard, A_Index, 1)
    if Lab_Invert_Char is upper
       Lab_Invert_Char_Out:= Lab_Invert_Char_Out Chr(Asc(Lab_Invert_Char) + 32)
    else if Lab_Invert_Char is lower
       Lab_Invert_Char_Out:= Lab_Invert_Char_Out Chr(Asc(Lab_Invert_Char) - 32)
    else
       Lab_Invert_Char_Out:= Lab_Invert_Char_Out Lab_Invert_Char
 }
 Send %Lab_Invert_Char_Out%
RETURN

hi, i don't know how to run this codes, its really helpful. can u tell me how to use this?



ozzii
  • Members
  • 167 posts
  • Last active: Oct 30 2015 04:54 PM
  • Joined: 23 Mar 2011
You copy your text (CTRL+C) and you start a Hotkey (CTRL+U for example)

techie108
  • Members
  • 250 posts
  • Last active: Jul 01 2017 06:17 AM
  • Joined: 05 Aug 2012

this is strange - the code works well in my browser (Chrome) but not in Win Word. any idea why? 

 

As for that code I posted earilier, changing the modified input to a paste rather than individual character sends obviously made it a lot faster..

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


cycleNumber := 1

#IfWinNotActive ahk_class XLMAIN

^+d::
If (cycleNumber==1)
{
ConvertUpper()
cycleNumber:= 2
}
Else If (cycleNumber==2)
{
ConvertLower()
cycleNumber:= 3
}
Else
{
ConvertSentence()
cycleNumber:= 1
}
Return





ConvertUpper()
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringUpper, Clipboard, Clipboard
	Len:= Strlen(Clipboard)
    SendInput, ^v ;pastes new text
	Send +{left %Len%}
    VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave
}

ConvertLower()
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringLower, Clipboard, Clipboard
	Len:= Strlen(Clipboard)
    SendInput, ^v ;pastes new text
	Send +{left %Len%}
    VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave
}

ConvertSentence()
{
	clipSave := Clipboard
	Clipboard = ; Empty the clipboard so that ClipWait has something to detect
	SendInput, ^c ;copies selected text
	ClipWait
	StringReplace, Clipboard, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
	StringLower, Clipboard, Clipboard
	Clipboard := RegExReplace(Clipboard, "(((^|([.!?]+\s+))[a-z])| i | i')", "$u1")
	Len:= Strlen(Clipboard)
    SendInput, ^v ;pastes new text
	Send +{left %Len%}
    VarSetCapacity(OutputText, 0) ;free memory
	Clipboard := clipSave
}

#IfWinNotActive

;RELOAD
!+^x::
   SplashTextOn,,,Updated script,
   Sleep,200
   SplashTextOff
   Reload
   Send, ^s
return


bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011

My TextPad 3.1.01 does it all.