• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Alias to extract a number from the clipboard

May 29, 2008
529
3
Groton, CT
#1
I have a tool which allows me to extract the sum of a single field onto the clipboard, but there are extra characters. When I activate the hot key that saves the sum, the clipboard then contains (e.g.) "Sum=-12,345.67". There's no + sign if the sum is nonnegative. But what I want to paste elsewhere is "-12345.67".
So I made this alias
Code:
alias num*clip=`echos %@rereplace[[^^0-9.-],,%@rereplace[-[^^0-9],,%@clip[0]]] > clip:`
The inner @rereplace removes any minus sign which is not followed by a digit, along with the nondigit; the outer @rereplace removes everything but digits, minus signs, and decimal points. It's not perfect but it does what I need.

I also put a shortcut on my desktop for target
Code:
"C:\Program Files\JPSoft\TCMD\tcc.exe" /i /c (echos %@rereplace[[^^0-9.-],,%@rereplace[-[^^0-9],,%@clip[0]]] > clip:)
 
Last edited:
#2
Is "Sum=" always there? If so, how about
Code:
echos %@eval[%@word["=",1,%@clip[0]]] > clip:
For example,
Code:
v:\> type clip:
Sum=-12,345.67

v:\> echos %@eval[%@word["=",1,%@clip[0]]] > clip:

v:\> type clip:
-12345.67
 
May 29, 2008
529
3
Groton, CT
#3
Is "Sum=" always there? If so, how about
Code:
echos %@eval[%@word["=",1,%@clip[0]]] > clip:
For example,
Code:
v:\> type clip:
Sum=-12,345.67

v:\> echos %@eval[%@word["=",1,%@clip[0]]] > clip:

v:\> type clip:
-12345.67
No, SUM= isn't always there. In my first usage, it was, but I found more useful places for the function, so I generalized it. I also remove the commas so that I don't have to use @EVAL in it.
 
Top Bottom