Search code examples
arraysstringautoit

Can't figure out how to declare a string array on multiple lines


This code was causing errors at runtime but would compile.

Local $acceptable[] = ["Chrome",_
                        "Firefox",_
                        "IE"]

It works if I move it all on one line. However, I want to declare many elements. How do I correctly declare it over multiple lines?


Solution

  • As per Language Reference - Comments (emphasis added):

    Although only one statement per line is allowed, a long statement can span multiple lines if an underscore "_" preceded by a blank is placed at the end of a "broken" line. String definition cannot be split in several lines, concatenation need to be used.

    Example (space before each underscore):

    #include <Array.au3>
    
    Global Const $g_aAcceptable[] = ["Chrome", _
                                     "Firefox", _
                                     "IE"]
    
    _ArrayDisplay($g_aAcceptable)