AHK Want to type number and have text expand around it so I can change number but text remains - autohotkey

I want to accomplish the following.
I want to write 2450 ddu1, where 2450 = the number and ddu1 = the trigger.
Writing the above would make it look like this:
Door delivery SEK 2450, based on your specified weight measurements.
The thing is that the numbers vary and so I need to be able to write the correct number and then the "text expansion phrase" to trigger the text.
I can expand text but I can't do it with my number remaining in the middle of the expanded text.
Thank you kindly for your help and effort.

There's no native support for dynamic hotstrings in AHK. But there's a great library that should fit your needs.
Check out Hotstrings, by Menixator.
Download that lib and try running this code:
#include Hotstring.ahk
; Listens for 1 or more digits, followed by "ddu1"
Hotstring("(\d+)\s+ddu1", "printPrice", 3)
return
; Prints a string with the digit in it
printPrice(param){
str_s := "Door delivery SEK "
str_e := ", based on your specified weight measurements."
out_s := str_s . param.value(1) . str_e
SendInput, %out_s%
}
Esc::ExitApp
It's triggered by typing one or more digits, followed by a space, followed by ddu1.
For example: 1 ddu1, 512 ddu1, 23123516161612 ddu1.

Related

Is there a way to insert N times the same characters

I can't find if vscode has a such failure. Is there a way to construct a string with N characters?
I explain myselft:
I need to wrote an empty string like this:
foobar = "1111111111111111";
There is 16 times characters '1'. Is there a way, like in Vim, to construct the line like this:
i wrote 'foobar = "' then i'd make a command to repeat 16 times the character 'i'.
I hope it's clear for you.
Here is an easy way using HyperSnips - a snippet extension that can use javascript to produce the output. First the demo:
The HyperSnips snippet:
snippet `"(.+)\*(\d+)=` "expand" A
``
let origStr = m[1];
let howMany = parseInt(m[2]);
let newStr = origStr.repeat(howMany);
rv=`"${newStr}`
``
endsnippet
This code goes inside a <yourLanguage>.hsnips file to have it run only in that language or all.hsnips to run in all files.
I made it to run inside a "" using this key: (.+)\*(\d+)=
The = is really the trigger - it runs automatically - you could change that to be something else. [The key could be shorter if you didn't care about digits being repeated.]
For more on setting up HyperSnips (which is pretty easy) see VSCode Advanced Custom Snippets
There currently is no native way, outside of copy/pasting.
You can use Repeat Paste:
Copies selected text and pastes repeatedly based on user input. Functions like Vim yank, paste, and repeat. For example, in Vim you would select the characters you want to copy then type 30p to paste the selected text 30 times.
Select a char and activate your command palette with CTRL + SHIFT + P and type 'Repeat Paste' and it will prompt you for the quantity.
You can assign a shortcut to this command
You can use the extension Regex Text Generator. You write a Regular Expression that generates your needed text
Type the following in the Generate Box
foobar = "1{16}";

Search string on numbers on Notepad++

I'm trying to do a Find and Replace action on my subtitles timings. I need to add an hour digit to all my timings. SRT files should display HH:MM:SS:FFF not MM:SS:FFF, as these are for WEBVTT files. I have added an example set of timings below.
This is my original layout 00:08.853 --> 00:11.158
This is the layout i desire 00:00:08.853 --> 00:00:11.158
Notice i have added an extra 00 to the beginning of each timing.
Can anyone help me with what formula I need to use in order to find all 00:00.000 --> 00:00.000 occurrences, barring in mind the exact numbers will change but the layout stays the same.
I've tried the following but the results come up as 0 occurrences:
Find ??:??.??? --> ??:??.???
Replace 00:??:??.??? --> 00:??:??.???
Hit Ctrl+H & tick Regular Expression
Find: \b(\d\d:\d\d\.)
(Find a word boundary, 2 digits, a colon, 2 digits, a period)
Replace with: 00:\1

How to add phonetic guides to all the texts at once?

I have an essay with roughly 1000 Chinese words. I want to add phonetic guide (Pin Yin) on top of each Chinese word.
Therefore, in MS Words, I use Phonetic Guide. However, Phonetic Guide only allows me to create Pin Yin for 20 to 30 words each time. I tried to look for a function which allows me to add phonetic guides for all the words at once, but I cannot find an answer online.
I also want to make the phonetic guide font bigger and create more space between the Chinese text and the Pin Yin.
Can any expert give me some lights?
Not familiar with this area, but the starting point is that you can invoke the Phonetic Guide dialog box and get it to create the pinyin for the selection. For example
Sub testInsertPhoneticGuide()
Call insertPhoneticGuide(Selection.Range)
End Sub
Sub insertPhoneticGuide(r As Word.Range)
Dim d As Word.Dialog
Dim lng As Long
Dim lngChars As Long
Dim r1 As Word.Range
Dim r2 As Word.Range
On Error Resume Next
Set d = Word.Dialogs(wdDialogPhoneticGuide)
Set r1 = r.Duplicate
r1.TextRetrievalMode.IncludeFieldCodes = False
For lng = Len(r1.Text) To 1 Step -1
Set r2 = r1.Characters(lng)
' Do not insert pinyin for any range that
' contains a field (this will prevent the code from re-inserting
' pinyin, but you can change the way this works if you like)
If r2.Fields.Count = 0 Then
r2.Select
d.Show 1
' Error 6031 says there's no text to pinyin
If Err.Number = 6031 Then
Err.Clear
Else
On Error GoTo 0
End If
End If
Next
Set r2 = Nothing
Set r1 = Nothing
Set d = Nothing
End Sub
As far as I can tell, there is no way to specify the font and size/position parameters in the dialog box. They are not "sticky". But the Phonetic guide replaces each suitable character by an { EQ } field that contains the pinyin and the original character. The EQ looks somehting like this:
{ EQ \* jc2 \* "Font:SimSun" \* hps11 \o\ad(\s\up 10(fā),发) }
so as long as you want the same font, size and positioning, you should be able to display all the field codes and use Word Find/Replace to modify those values in every EQ field (or you could add code to modify the values for each character that you pinyin.
NB, there is also a PhoneticGuide() member of Word's Range object that lets you specify the pinyin text and the positioning parameters. However, to use that you would have to get the pinyin text somehow - the only way I know within Word is actually to use the Phonetic Guide dialog to insert it, but I imagine the necessary info for each character is available on the web.
In case anybody comes to this question again, after searching for a solution for a while I managed to add pinyin to my entire Chinese document by using the following two tools:
1) Open Office
2) The OO Pinyin Guide Extension for Open Office.
Hope this helps : )

Put Alphabetical series in formula using HTML as Text interpretation

I am using a 3 way formula to put notes below the group footer of my Crystal Report. Please see below example for illustration
1. Text
a. Text
b. Text
2. Text
a. Text
b. Text
3. Text
a. Text
b. Text
c. Text
I was able to put the numerical series using a variable and increment it by 1, however in letters, I have seen a code to something like
chrw(96 + i) //where i is 1 based
But that wont work because my text interpretation is on HTML, are there alternatives? or conversion of the code for it to take effect in my formula.
chrw(ascw("`") + (var2 := var2+1))
the code above worked for me!, just set the variable var2 and initialize to 0 value. Do some conditioning to create an indention effect.

Can I make a macro in n++ that does a search/replace?

I'm new to n++, but I have been most impressed with this tool so far. I've been trying to record a macro that do a search/replace, but the 'search' part seems to have the initial search text from the recording 'hard-coded' in the macro.
What I want is:
Manually locate the cursor at the beginning of the first line of a fixed format code segment, then Macro actions:
move cursor two lines down
move cursor right x characters
mark charters from pos x to x+n
search and replace all occurrences of the selected text with "{p_'selected text'}"
In an more advanced version, I'd like to add some logic to step 4: only execute the replace part if the # of occurrences are > 1 (e.g. by first adding a count statement, but I'm not sure how to obtain the returned count # from the dialog box)
Is this possible?
While I'm a big fan of Notepad++, this sounds like something I would accomplish with AutoHotKey. You would select the text and copy it to the clipboard. AutoHotKey would read the clipboard, replace the text as you desire, and either replace the clipboard contents, or send it back to your document. Let me know if you would like to go that route.