[library] TF: Text files & Variables (strings) v3.7

Post your working scripts, libraries and tools
Guest

Re: [library] TF: Text files & Variables (strings) v3.7

07 Feb 2018, 05:19

You need to learn the basics of AutoHotkey - you can't just use A_LoopReadLine like that, you need to have it "outside" of the quotes otherwise it won't be "translated" in the contents. As A_LoopReadLine may also contain new line characters you may need to trim

Code: Select all

TF_RegExReplace("!" A_LoopFileFullPath,"im)\b" trim(A_LoopReadLine,"`r`n") "\b","lock") ; use trim to remove trailing new line chars which may interfere
If it is a word list you are processing you can do it all in one go but you need to study and learn RegEx (hint|list|of|words|like|this) - see regex docs linked to above.
User avatar
Tomer
Posts: 263
Joined: 21 Aug 2016, 05:11

Re: [library] TF: Text files & Variables (strings) v3.7

07 Feb 2018, 05:53

Thanks Guest :bravo:

I know i should have keep the variables outside the quotes from my first exmaple :lol: :lol: :lol:
(although i posted my sample code into the quotes just so you see my sample code).

anyway, what i needed is Trim :)

ps. why you using new lines (,"`r`n") ?
tested it without it and works as well
hasantr
Posts: 95
Joined: 05 Apr 2016, 14:18

Re: [library] TF: Text files & Variables (strings) v3.7

26 Jul 2018, 15:15

I have not been able to use it. Can someone explain it in detail? Could you give me a working example? I really need this library. I'm new to Autohotkey. But I'm so bored with that.

How do we include the library in our work? I did, but things did not work and things went wrong. "C: \ Users \ hasan \ Desktop \ Deneme.ahk (19): ==> Call to nonexistent function.
     Specifically: TF_Find (FilePath, "", "", "i) \ Q" SearchText "\ E", 0, 1)

Thanks.
Guest

Re: [library] TF: Text files & Variables (strings) v3.7

27 Jul 2018, 02:33

Its pretty straight forward.

You can either use #include or use the LIB folder:

1. You can either use #include path-to-your-copy-of\tf.ahk * in your script

* if you have your script and tf.ahk in the same folder #include tf.ahk will work of course

2. Place a copy of tf.ahk in one of the following folders on your computer:

%A_ScriptDir%\Lib\ ; Local library - requires [v1.0.90+].
%A_MyDocuments%\AutoHotkey\Lib\ ; User library.
directory-of-the-currently-running-AutoHotkey.exe\Lib\

Source & More info https://autohotkey.com/docs/Functions.htm#include

Working sample script

Code: Select all

FileDelete, tftestfile123.txt
FileAppend, 
(
01 AutoHotkey is a free, open-source utility for Windows. With it, you can:
02 - Automate almost anything by sending keystrokes and mouse clicks.
03 - Create hotkeys for keyboard, joystick, and mouse. Virtually any key, button, or combination can become a hotkey.
04 - Expand abbreviations as you type them. For example, typing "btw" can automatically produce "by the way".
05 - Create custom data-entry forms, user interfaces, and menu bars. See GUI for details.
06 - Remap keys and buttons on your keyboard, joystick, and mouse.
07 - Respond to signals from hand-held remote controls via the WinLIRC client script.
08 - Convert any script into an EXE file that can be run on computers that don't have AutoHotkey installed.
), tftestfile123.txt


; TF_Find(FilePath, "", "", "i)\Q" SearchText "\E")
MsgBox % TF_Find("tftestfile123.txt", "", "", "abbreviations") ; remember it is case sensitive by default
MsgBox % TF_Find("tftestfile123.txt", "", "", "and",0) ; return a CSV list of all lines with 'and'
MsgBox % TF_Find("tftestfile123.txt", "5", "", "AutoHotkey") ; start at line 5 so it skips the first result e.g. line 1 here

myvar:="autohotkey" ; lowercase

MsgBox % TF_Find("tftestfile123.txt", "", "", "i)\Q" myvar "\E",0,1) ; return the text of all found lines 
Karner
Posts: 6
Joined: 25 Nov 2018, 04:12

Re: [library] TF: Text files & Variables (strings) v3.7

25 Nov 2018, 04:32

Hello to all, my newbie post to new AHK forum...

I am trying to reformat MS Outlook's (multi-) email reply to a more readable layout...

I am new to TF too, reading a lot, but couldn't solve following problem:

How to find and replace rows containing text with various parts (bold/underlined):
Am 22.11.2018 um 12:36 schrieb "name1@mail.com" <name1@mail.com>:
...
Am 11.10.2018 um 11:11 schrieb "nam22@mail22.de" <nam22@mail22.de>:
...
It shall result in:
-----Original-Message-----
Am 22.11.2018 um 12:36 schrieb "name1@mail.com" <name1@mail.com>:
...
-----Original-Message-----
Am 11.10.2018 um 11:11 schrieb "nam22@mail22.de" <nam22@mail22.de>:
...
with -----Original-Message----- inserted.

Thx for help and best regards!
ahk7
Posts: 145
Joined: 06 Nov 2013, 16:35

Re: [library] TF: Text files & Variables (strings) v3.7

25 Nov 2018, 07:35

Be sure to make backups so you don't loose the source material. This works with a text file so not sure how your source material looks (if its msg, eml or html it can be a lot trickier due to all the formatting).

Code: Select all

FileDelete, tf-testemail.txt ; create a test file
FileAppend, 
(
Am 22.11.2018 um 12:36 schrieb "name1@mail.com" <name1@mail.com>:
lorem impsum
Am 11.10.2018 um 11:11 schrieb "nam22@mail22.de" <nam22@mail22.de>:
doler factum
), tf-testemail.txt

TF_RegExReplace("tf-testemail.txt","iUm)^Am (\d{1,2})\.(\d{1,2})\.(\d{4})","-----Original-Message-----`nAm $1.$2.$3")

; now you should have a file tf-testemail_copy.txt which looks like you want it, if you use TF_RegExReplace("!tf-testemail.txt",.... it will OVERWRITE the source file
Look up meaning of the RegExReplace options here https://autohotkey.com/docs/misc/RegEx-QuickRef.htm
Karner
Posts: 6
Joined: 25 Nov 2018, 04:12

Re: [library] TF: Text files & Variables (strings) v3.7

25 Nov 2018, 12:27

Thank you very much, it is working for example file :) .

But how to append function to clipboard content?
Something like this?
Clipboard:=TF_RegExReplace(Clipboard...
ahk7
Posts: 145
Joined: 06 Nov 2013, 16:35

Re: [library] TF: Text files & Variables (strings) v3.7

25 Nov 2018, 12:46

Yes, that should work.
Karner
Posts: 6
Joined: 25 Nov 2018, 04:12

Re: [library] TF: Text files & Variables (strings) v3.7

25 Nov 2018, 13:55

Code: Select all

TF_RegExReplace(Clipboard,"iUm)^Am (\d{1,2})\.(\d{1,2})\.(\d{4})","-----Original-Message-----`nAm $1.$2.$3")
is not working :? There must be a syntax misunderstanding!?
Thx + regards.
ahk7
Posts: 145
Joined: 06 Nov 2013, 16:35

Re: [library] TF: Text files & Variables (strings) v3.7

25 Nov 2018, 14:14

No it works, as I mentioned if it is a different format (and the clipboard can hold various formats and it doesn't have to include text as such) it may not work. If it is only the clipboard you're working with you have no need for TF as TF simply wraps the standard AHK RegExReplace function

Code: Select all

Clipboard=
(join`r`n
Am 22.11.2018 um 12:36 schrieb "name1@mail.com" <name1@mail.com>:
lorem impsum
Am 11.10.2018 um 11:11 schrieb "nam22@mail22.de" <nam22@mail22.de>:
doler factum
)

clipboard:=TF_RegExReplace(clipboard,"iUm)^Am (\d{1,2})\.(\d{1,2})\.(\d{4})","-----Original-Message-----`nAm $1.$2.$3")

MsgBox % Clipboard
if remove TF_ its the same

Code: Select all

clipboard:=RegExReplace(clipboard,"iUm)^Am (\d{1,2})\.(\d{1,2})\.(\d{4})","-----Original-Message-----`nAm $1.$2.$3")

Return to “Scripts and Functions”

Who is online

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