FileSelectFile, file, , , 请选择ini文件, ini配置文件(*.ini) ;选择文件 if file= { MsgBox, 0, 错误, 您为选择任何文件 Reload } sections = FileRead, filecontent, %file% ;加载文件到变量 StringSplit, line, filecontent, `n, , ;用函数分割变量为数组 Loop ;循环 { if A_Index > %line0% Break content = % line%A_Index% ;赋值当前行 StringReplace, content, content, `r, , All ;替换特殊字符 FSection := RegExMatch(content, "\[.*\]") ;正则表达式匹配section if FSection = 1 ;如果找到 { TSection := RegExReplace(content, "\[(.*)\]", "$1") ;正则替换并赋值临时section $为向后引用 sections = %sections%%TSection%| ;用|串接所有section 方便使用列出 %TSection%keys = } Else { FKey := RegExMatch(content, ".*=.*") ;正则表达式匹配key if FKey = 1 { TKey := RegExReplace(content, "(.*)=.*", "$1") ;正则替换并赋值临时key StringReplace, TKey, TKey, ., _, All TKey2=%Tkey%| %TSection%keys = % %TSection%keys TKey2 ;;用|串接当前section下所有key 方便使用列出 TValue := RegExReplace(content, ".*=(.*)", "$1") ;正则替换并赋值临时value %TSection%_%TKey%=%TValue% } } } ListVars ;调试情况 列出所有变量 Pause
49 queries in 1.332 seconds |