Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Alias to extract a number from the clipboard

May
572
4
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:
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
 
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.
 
Back
Top