IfInString trouble Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
GammaSerpentisFTW
Posts: 5
Joined: 17 Dec 2017, 09:50

IfInString trouble

18 Jan 2018, 07:32

It's very strange and I don't understand, how can it be so. Please help, I'm almost in despair, really.
I have a .txt with some lines with text and blacklist.txt with blacklisted words. I want to get rid of the lines with blacklisted words in them. Simple, right?
Here is what I did:

Code: Select all

; loading the input lines into array
FileRead, InputDump, input.txt
InputArray := StrSplit(InputDump, "`n")
InputLines := InputArray.MaxIndex()

; loading blacklisted words into array
FileRead, BlacklistDump, blacklist.txt
BlacklistArray := StrSplit(BlacklistDump, "`n")
BlacklistLines := BlacklistArray.MaxIndex()

j := 1
Loop
	{
	CurrentString := InputArray[j]
	IsBlacklisted := 0
	Loop
		{
		BlacklistWord := BlacklistArray[A_Index]
		IfInString, CurrentString, %BlacklistWord%
			{
			IsBlacklisted := 1
			Break
			}
		; this is just for debug really
		Else
			FileAppend, %CurrentString% DOESNT CONTAIN %BlacklistWord%`n, impossibruuuu.txt
		}
	Until (A_Index = BlacklistLines)
	
	If (IsBlacklisted = 0)
		FileAppend, %CurrentString%`n, output.txt
	
	j++
	}
Until (j = InputLines)
Now, for example I have such input.txt:

Code: Select all

Blah Blah Blah
Blah FISH Blah
Poke Poke Mon
Blah Blah Blah
SHIFT FISH blah
Blah FISH SHIFT
Blah FISH Blah
And this is my blacklist.txt:

Code: Select all

Fish
Shift
I get this output.txt:

Code: Select all

Blah Blah Blah
Blah FISH Blah
Poke Poke Mon
Blah Blah Blah
And now to the most funny part: in the code above I had IfInString, CurrentString, %BlacklistWord% and after that I had Else FileAppend, %CurrentString% DOESNT CONTAIN %BlacklistWord%`n, impossibruuuu.txt, right? And between them there was no alteration of ANY of those 2 variables, right? But I have this in my impossibruuuu.txt:

Code: Select all

Blah FISH Blah
 DOESNT CONTAIN Fish
SHIFT FISH blah
 DOESNT CONTAIN Fish
Blah FISH SHIFT
 DOESNT CONTAIN Fish
Please, help.
just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: IfInString trouble  Topic is solved

18 Jan 2018, 08:40

The default line break on Windows consists of two characters: carriage return `r and line feed `n. So use

Code: Select all

BlacklistArray := StrSplit(BlacklistDump, "`n", "`r")
to remove the `r from the result.
GammaSerpentisFTW
Posts: 5
Joined: 17 Dec 2017, 09:50

Re: IfInString trouble

18 Jan 2018, 09:03

just me wrote:The default line break on Windows consists of two characters: carriage return `r and line feed `n. So use

Code: Select all

BlacklistArray := StrSplit(BlacklistDump, "`n", "`r")
to remove the `r from the result.
Indeed, that helped! Thank you!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 281 guests