Khalil
Khalil

Reputation: 311

Autohotkey string evaluation / comparison not working as expected

category_generic = book, book_asl, author, author_asl, publisher
StringSplit, categories_array, category_generic, `,
Loop 
{
    category := categories_array%a_index%
    do_my_amazing_stuff
    if (category = "author")
    {
        do_some_more_amazing_stuff
    }
}

Problem: The evaluation: if (category = "author") never holds true, despite the fact that the loop parses through the entire content of the array. Moreover, it can write out the categories correctly as they appear in the array, out to a file. I tried billion different versions, none of it works. Can someone explain to me why the evaluation does not get evaluated?

Upvotes: 0

Views: 1261

Answers (1)

MCL
MCL

Reputation: 4065

The problem are the spaces in your list. AHK won't magically drop them. If you look closely, the spaces after each list item appear in your output file, too. Either leave them out in the first place or discard them in some way. StringSplit provides such a functionality with OmitChars:

StringSplit, categories_array, category_generic, `, %A_SPACE%

Upvotes: 3

Related Questions