Help with TF_find Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
corcova
Posts: 14
Joined: 23 Apr 2022, 11:59

Help with TF_find

Post by corcova » 18 May 2022, 16:41

Hello guys! Im trying to use the TF_find from the TF: Textfile & String Library for AutoHotkey https://github.com/hi5/TF

I need to know which is the number line of a specific string in a text file
In the following test I need it to say "2". But it keeps show 0 as result.. what im getting wrong?

Code: Select all

numpad4::
list=
(
1,17/05/22 15:49,+55 31 9443-6698
2,17/05/22 17:03,+55 22 98122-3378
2,17/05/22 16:56,+55 31 7575-6785
)

SearchText:="+55 22 98122-3378"
MsgBox % TF_Find(list, 1, 0, SearchText, 1, 0)
return
[Mod edit: [code][/code] tags added.]

User avatar
boiler
Posts: 16792
Joined: 21 Dec 2014, 02:44

Re: Help with TF_find  Topic is solved

Post by boiler » 18 May 2022, 17:51

As the instructions for TF_Find() that you linked yourself say, it uses Regular Expressions for the pattern (see the AHK command RegExMatch for more info about this), and certain characters have special meaning and need to be escaped by preceding them with a backslash (\) if you want to represent them as a literal character. The + character is one of those that needs to be escaped, so changing this line in your code as shown will result in a return value of 2:

Code: Select all

SearchText:="\+55 22 98122-3378"

Or if you don't want to have to bother with looking for characters that need escaping, you can use this modification to the call to TF_Find() where the \Q and \E will cause everything in between to be treated as literal characters:

Code: Select all

list=
(
1,17/05/22 15:49,+55 31 9443-6698
2,17/05/22 17:03,+55 22 98122-3378
2,17/05/22 16:56,+55 31 7575-6785
)

SearchText:="+55 22 98122-3378"
MsgBox % TF_Find(list, 1, 0, "\Q" SearchText "\E", 1, 0)
return

corcova
Posts: 14
Joined: 23 Apr 2022, 11:59

Re: Help with TF_find

Post by corcova » 18 May 2022, 18:51

Perfect, thank you very much for your help and patience. Obrigado!

Post Reply

Return to “Ask for Help (v1)”