Increase/decrease number in selected text Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Haan
Posts: 12
Joined: 14 Nov 2020, 19:34

Increase/decrease number in selected text

14 Nov 2020, 19:58

Hi,

I still don't understand how to use RegEx in AutoHotkey, and need help, please.

I wanna copy numbers like this: 21001/2020 (xxxx/year)

and past this: 21002/2020

and when I copy 21002/2020
i want to paste: 21003/2020

So, I need always "plus one" to the sequence (21001+1; 21002+1, etc), keeping the year the same,



In my example, i will already get in clipboard a number, for example, 22333/2020
when i paste, it needs to be pasted 22334/2020

Code: Select all

RegExMatch(clipboard,"I don't Know How to Worh with RegEx",Number)
      NewNumber:=Number1+1
      OldNumber:=NewNumber-1
      Clipboard:=RegExReplace(clipboard, OldNumber, NewNumber)
      Sleep 100
      Send ^v
How to do the trick???
I appreciate any help.
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Increase/decrease number in selected text  Topic is solved

14 Nov 2020, 20:25

hope it helps

Code: Select all

Clipboard := "21001/2020"
RegExMatch(Clipboard, "(\d+)/(\d+)", number)
Clipboard := number1+1 "/" number2
MsgBox % Clipboard
Haan
Posts: 12
Joined: 14 Nov 2020, 19:34

Re: Increase/decrease number in selected text

15 Nov 2020, 06:21

AlphaBravo wrote:
14 Nov 2020, 20:25
hope it helps

Code: Select all

Clipboard := "21001/2020"
RegExMatch(Clipboard, "(\d+)/(\d+)", number)
Clipboard := number1+1 "/" number2
MsgBox % Clipboard
Thank You AlphaBravo!!!
But I stiil have a problem. Look at this, please:

Code: Select all

#SingleInstance force

\::
	RegExMatch(Clipboard, "(\d+)/(\d+)", number)
	Clipboard := number1+1 "/" number2
	Send, ^v
	return
When I copy number at this range: 00001/2020. The script pastes : 2/2020
Another example, when I copy 01000/2020, it pastes: 1001/2020. I need keep the format: 00002/2020 and 01002/2020. Keeping zeros.
Any idea? I am greatful for your answer!!!
sofista
Posts: 654
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Increase/decrease number in selected text

15 Nov 2020, 07:04

Haan wrote:
15 Nov 2020, 06:21
When I copy number at this range: 00001/2020. The script pastes : 2/2020
Another example, when I copy 01000/2020, it pastes: 1001/2020. I need keep the format: 00002/2020 and 01002/2020. Keeping zeros.
Any idea? I am greatful for your answer!!!
Hi:
Format will do the trick, as follows

Code: Select all

Clipboard := "00001/2020"
RegExMatch(Clipboard, "(\d+)/(\d+)", number)
Clipboard := Format("{:05}/{}", number1+1, number2)
MsgBox % Clipboard

;00002/2020
Haan
Posts: 12
Joined: 14 Nov 2020, 19:34

Re: Increase/decrease number in selected text

15 Nov 2020, 07:57

sofista wrote:
15 Nov 2020, 07:04
Haan wrote:
15 Nov 2020, 06:21
When I copy number at this range: 00001/2020. The script pastes : 2/2020
Another example, when I copy 01000/2020, it pastes: 1001/2020. I need keep the format: 00002/2020 and 01002/2020. Keeping zeros.
Any idea? I am greatful for your answer!!!
Hi:
Format will do the trick, as follows

Code: Select all

Clipboard := "00001/2020"
RegExMatch(Clipboard, "(\d+)/(\d+)", number)
Clipboard := Format("{:05}/{}", number1+1, number2)
MsgBox % Clipboard

;00002/2020
YOU GUYS ARE AWESOME!!!!!!!!!!!!!!!!!!!!!!!!! :bravo: :bravo: :bravo: :bravo: :bravo:
I spent many hours with this questions and don't get any solution working alone. This community is fantastic.
Now, I will understand this script and very well and make another ones. Any doubt that I can't figure out myselg, I will come back here asking for help!
Thank you all again. AlphaBravo and sofista :superhappy: :superhappy: :dance: :wave: :wave: :wave:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 290 guests