mIRC Home    About    Download    Register    News    Help

Print Thread
#267420 30/06/20 02:00 PM
Joined: Jun 2020
Posts: 4
B
Self-satisfied door
OP Offline
Self-satisfied door
B
Joined: Jun 2020
Posts: 4
I am having trouble with this line :

/set %Variable1 $READ(C:\document.txt,w,* $+ %variable2 $+ *)

where I am trying to search document.txt for the first occurrence of the text %variable2 which will likely be part of a longer line. The %variable1 being set to the whole of that line.

I'm sure this used to work, but for some reason now doesn't. Has the syntax changed since I first wrote the line six or seven years ago?

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
Still the same, perhaps
https://en.wikichip.org/wiki/mirc/identifiers/$read
will jog your memory of what you're doing wrong. Things i see from your example
1. For a long time, Windows has blocked creating files in root of c: drive, so this fails if file doesn't exist. If file is in $mircdir it doesn't need the path. If it's in a subfolder of that, the path can be relative.
2. if %variable is null, then your search is for ** which matches the 1st line
3. ALWAYS use the nt switches unless you have a specific reason not to. Without the 'n' it evaluates words beginning with percent or dollar. Without the 't', if the 1st line is a number, that makes $read think that number is a replacement for $lines(filename) and can cause it to ignore the tail end of the file.

Joined: Jun 2020
Posts: 4
B
Self-satisfied door
OP Offline
Self-satisfied door
B
Joined: Jun 2020
Posts: 4
1. I simplified the location of the text file for the purposes of the question. Its actually:

C:\Users\paul\Desktop\Mirc\questions.txt

The file does exist, and if I change the %variable2 in the $read command to something specific eg......"the house is red" it finds the "the house is red" without an issue.
I tested and echo the %variable1 prior to the $read and it is legitimate and not null.
I have tried the ntw switch as I had found the wikichip page using google , prior to your reply, and tried it just in case. The first line of the txt document isnot numeric though.

Last edited by BaronSamedi; 30/06/20 03:23 PM.
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
So is it working or not? You didn't give an example of something that isn't working. Assuming the folder you mentioned is the same folder where $mircini shows your mirc.ini is located, then the path isn't even needed at all. You can put the filename into %variable3 then confirm whether $isfile(%variable3) is $true or $false. You can also check the value of $readn to see if it's non-zero, because * $+ $null $+ * will match a blank line or even a line containing only spaces, and both will cause echo to fail.
There are another couple cases where the match would fail to return the right thing.
4. when your search string and the file string don't have a substring match due to extra spaces. If the file has 2 spaces between "the" and "house" but your search text only has 1 space, then no match.
5. There is no switch for a case-sensitive match, so if it's matching NICK when you want only a case-sensitive match with Nick, you'd need to use the regex switch r which defaults to case-sensitive, but that uses different syntax than wildcard.


Link Copied to Clipboard