Description
Creates HTML alike list (with new lines, bullets, indentation and whatnot) from array. I'm using mostly it for MsgBox when there's need of listing things, i.e. something failed because
- . Of course you can do it manually, but I think it keeps code cleaner. This way also ensures the lists will look the same, which is just nice for users.
Parameters- (array) items - array of items
- (int) indent - indentation level (default: 1; 0 for no indentation)
- (str) liSymbol - list symbol, i.e. prefix of item (default: "•")
Result
String with ready to use list.
Note 1: the indentation is two spaces. I didn't use tabulation character, as it's often too big.
Note 2: the list starts with first item, ends with new line character. For [whole] list suffix and prefix you'd need to provide following elements: [Prefix][New line char]- [Suffix]. It's inconsistent with HTML (HTML <ul> doesn't need \n before list) because cases when you want to give just list, without prefix, so new line character would be wrong to use. To make it add new character before each list, add "out := "`t"" as a first line of body function.
CodeExampleCode: Select all
makeList(items, indent = 1, liSymbol = "•") { indStr := if indent > 0 Loop, %indent% indStr .= " " for k,item in items out .= indStr liSymbol " " item "`n" return out }
CodeResultCode: Select all
MsgBox % makeList(["Foo", "Bar", "Foobar"])
CodeCode: Select all
• Foo • Bar • Foobar
ResultCode: Select all
MsgBox % "Update failed. Possible causes: `n" makeList(["Solar flares", "Server is down", "You broke it"],5,"-") "Please try again later."
Code: Select all
Update failed. Possible causes: - Solar flares - Server is down - You broke it Please try again later.