Page 1 of 1

Help with TF_find

Posted: 18 May 2022, 16:41
by corcova
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.]

Re: Help with TF_find  Topic is solved

Posted: 18 May 2022, 17:51
by boiler
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

Re: Help with TF_find

Posted: 18 May 2022, 18:51
by corcova
Perfect, thank you very much for your help and patience. Obrigado!