【已解决,谢谢afan老师】读ini为什么只读到7条?
本帖最后由 wangms 于 2014-7-12 17:27 编辑#include <Array.au3>
GUICreate("列表视图 - 项目", 800, 500, -1, 180) ;, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0x00E0FFFF) ; 将改变背景颜色
Local $idListview = GUICtrlCreateListView("关键字|--------命令---------|-----参数-----|----起始位置----| 备注 |打开方式", 10, 10, 780, 450);,$LVS_SORTDESCENDING)
Dim $var = IniReadSection(@ScriptDir & '\1.ini', 'FastStart'), $item, $i
_ArrayDisplay($var)
For $i = 1 to $var
$item[$i-1] = GUICtrlCreateListViewItem($var[$i] & '|' & $var[$i], $idListview)
ReDim $item[$i+1]
next
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case -3
ExitLoop
EndSwitch
WEnd读ini为什么只读到7条?求教各位老师哪儿出问题啦! 自己顶一下,等老师们来帮我看看。。。 仔细看了一下,有=号的读出了、没有=号的没读出来。
请教各位老师咋样将如下格式以‘|’为分隔读到数组,该咋样写?
mydn|explorer|::{20D04FE0-3AEA-1069-A2D8-08002B30309D} ||||||我的电脑
hsz|explorer|::{645FF040-5081-101B-9F08-00AA002F954E} ||||||回收站
wslj|explorer|::{208D2C60-3AEA-1069-A2D7-08002B30309D} ||||||网上邻居
wllj|explorer|::{7007ACC7-3202-11D1-AAD2-00805FC1270E} ||||||网络连接
print|explorer|::{2227A280-3AEA-1069-A2DE-08002B30309D} ||||||打印机与传真
rwjh|explorer|::{D6277990-4C6A-11CF-8D87-00AA0060F5BF} ||||||任务计划
bd|C:\Program Files\Mozilla Firefox\firefox.exe|http://www.baidu.com/baidu?wd=%s&cl=3
gg|C:\Program Files\Mozilla Firefox\firefox.exe|https://www.google.com.hk/search?inlang=zh-CN&newwindow=1&safe=strict&hl=zh-CN&q=%s&oq=wome&gs_l=serp.3.2.0i2l10.17420.17986.0.20758.4.4.0.0.0.0.305.488.0j1j0j1.2.0....0...1c.1.45.serp..2.2.484.v3a8e3RZXxU
dict|C:\Program Files\Mozilla Firefox\firefox.exe|http://dictionary.reference.com/search?q=%s
iciba|C:\Program Files\Mozilla Firefox\firefox.exe|http://www.iciba.com/search?s=%s&t=word&lang=utf-8
mywd|explorer|::{450D8FBA-AD25-11D0-98A8-0800361B1103} ||||||我的文档
sx|C:\Program Files\Mozilla Firefox\firefox.exe|http://www.acronymfinder.com/af-query.asp?String=exact&Acronym=%1|||||||缩写搜索
fy|C:\Program Files\Mozilla Firefox\firefox.exe|http://fanyi.baidu.com/translate#en/zh/%s
lx|C:\Program Files\Mozilla Firefox\firefox.exe|http://www.55188.com/forum-68-1.html
chen|C:\Program Files\Mozilla Firefox\firefox.exe|http://www.worldlingo.com/wl/mstranslate/UP26384/T1/P2/l/microsoft/computer_translation.html?wl_lp=ZH_CN-EN&wl_fl=0&wl_rurl=http%3A%2F%2F%s%2F&wl_url=%s&wlg_table=-3
ruen|C:\Program Files\Mozilla Firefox\firefox.exe|http://www.translate.ru/url/tran_url.asp?lang=ru&url=%s&direction=re&template=General&cp1=NO&cp2=NO&autotranslate=on&transliterate=on&psubmit2.x=50&psubmit2.y=12
gh|C:\Program Files\Mozilla Firefox\firefox.exe|https://vip.icbc.com.cn/icbc/perbank/index.jsp
jh|C:\Program Files\Mozilla Firefox\firefox.exe|https://ibsbjstar.ccb.com.cn/app/V5/CN/STY1/login.jsp
nh|C:\Program Files\Mozilla Firefox\firefox.exe|http://www.abchina.com/cn/wydl/grwydl/default.htm#
zh|C:\Program Files\Mozilla Firefox\firefox.exe|https://ebsnew.boc.cn/boc15/login.html
ie|C:\Program Files\Internet Explorer\IEXPLORE.EXE filereadline stringsplit 谢谢指点!以上ini文件是TypeAndRun的配置文件,AU3应该有比较直接的办法吧。本想按http://www.autoitx.com/thread-9368-1-1.html六楼afan老师指点的_FileReadToArray来试试,可帮助文档实例有错误,无法参照。 把它当一般文本文件读取就行了GUICreate("列表视图 - 项目", 800, 500, -1, 180) ;, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0x00E0FFFF) ; 将改变背景颜色
Local $idListview = GUICtrlCreateListView("关键字|--------命令---------|-----参数-----|----起始位置----|-|-|-|-| 备注 |打开方式", 10, 10, 780, 450);,$LVS_SORTDESCENDING)
Local $sIni = FileRead(@ScriptDir & '\1.ini')
$sIni = StringRegExpReplace($sIni, '(?mi)[\s\S]*?^\h*\\V*\v+([\s\S]+?)(?=\r\n\h*\[|\z)[\s\S]*', '\1')
Local $aLine = StringRegExp($sIni, '\V+', 3)
Local $i
If Not @error Then
For $i = 0 To UBound($aLine) - 1
GUICtrlCreateListViewItem($aLine[$i], $idListview)
Next
EndIf
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case -3
ExitLoop
EndSwitch
WEnd
本帖最后由 wangms 于 2014-7-12 17:31 编辑
回复 6# afan
果真盼得afan老师出手,真是荣幸!如此复杂的正则,若非高手出手自己是万万搞不定的。再次谢谢老师啦!! 本帖最后由 wangms 于 2014-7-12 17:40 编辑
想再次请教老师,将已分开好的(也就是GUICtrlCreateListViewItem显示出的样子)放在数组里,好进行调用,该怎样写? 定义一个二维数组,可在创建 Item 时同时填充#include <Array.au3>
GUICreate("列表视图 - 项目", 800, 500, -1, 180) ;, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0x00E0FFFF) ; 将改变背景颜色
Local $idListview = GUICtrlCreateListView("关键字|--------命令---------|-----参数-----|----起始位置----|-|-|-|-| 备注 |打开方式", 10, 10, 780, 450);,$LVS_SORTDESCENDING)
Local $sIni = FileRead(@ScriptDir & '\1.ini')
$sIni = StringRegExpReplace($sIni, '(?mi)[\s\S]*?^\h*\\V*\v+([\s\S]+?)(?=\r\n\h*\[|\z)[\s\S]*', '\1')
Local $aLine = StringRegExp($sIni, '\V+', 3)
Local $i, $afg, $j
If Not @error Then
Local $aData
For $i = 0 To UBound($aLine) - 1
GUICtrlCreateListViewItem($aLine[$i], $idListview)
$afg = StringSplit($aLine[$i], '|', 1)
For $j = 1 To $afg
$aData[$i][$j - 1] = $afg[$j]
Next
Next
EndIf
_ArrayDisplay($aData, '')
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case -3
ExitLoop
EndSwitch
WEnd
我刚一晚苦苦摸索,是那样的艰难!在您那儿就一撮而就,一气呵成!佩服佩服!!谢谢!谢谢!谢谢老师! 正则的强大,膜拜 本帖最后由 wangms 于 2014-7-13 12:26 编辑
afan老师,您干脆好人做到底、送佛送到西天,请将__FileReadToArray()代码规范成通用函数格式:#include <Array.au3>
Const $sFilePath = @ScriptDir & "\Config.ini"
Local $aList = __FileReadToArray($sFilePath)
_ArrayDisplay($aList, '')
;===================读'|'分隔符非标准ini文件成二维数组的函数==================================
Func __FileReadToArray($sFile)
Local $sIni = FileRead($sFile)
$sIni = StringRegExpReplace($sIni, '(?mi)[\s\S]*?^\h*\\V*\v+([\s\S]+?)(?=\r\n\h*\[|\z)[\s\S]*', '\1')
Local $aLine = StringRegExp($sIni, '\V+', 3)
;Local $aLine = FileReadToArray($sFile) ;以上三句换成这一句看看咋样,可以哦,不过还是用大师的三句保险(尽管不明白究竟起到什么作用),至少可以除空行
Local $i, $afg, $j
If Not @error Then
Local $aData
For $i = 0 To UBound($aLine) - 1
$afg = StringSplit($aLine[$i], '|', 1)
For $j = 1 To $afg
$aData[$i][$j - 1] = $afg[$j]
Next
Next
ReDim $aData
EndIf
Return $aData
EndFunc;==>__FileReadToArray 回复 12# wangms
不是老师,是老菜鸟而已~~
比较复杂的正则其实是提取字段的。#include <Array.au3>
Const $sFilePath = @ScriptDir & "\Config.ini"
Local $aList = __IniReadToArray($sFilePath, 'FastStart')
_ArrayDisplay($aList, '')
;===================读'|'分隔符非标准ini文件成二维数组的函数==================================
Func __IniReadToArray($sIniFile, $Section, $sDecimal = '|')
;ini文件路径 ;字段名 ;分隔符
Local $sIni = FileRead($sIniFile)
Local $_Section = StringRegExpReplace($Section, '^\h*(.+?)\h*$', '$1')
$_Section = StringRegExpReplace($_Section, '(\.|\||\*|\?|\+|\(|\)|\{|\}|\[|\]|\^|\$|\\)', '\\$1')
$sIni = StringRegExpReplace($sIni, '(?mi)[\s\S]*?^\h*\[' & $_Section & '\]\V*\v+([\s\S]+?)(?=\r\n\h*\[|\z)[\s\S]*', '\1')
Local $aLine = StringRegExp($sIni, '\V+', 3)
If @error Then Return SetError(1)
Local $i, $afg, $j, $iMax = 1, $iC = 1
Local $aData[$iMax]
For $i = 0 To UBound($aLine) - 1
$afg = StringSplit($aLine[$i], $sDecimal, 1)
For $j = 1 To $afg
If $afg > $iMax Then
$iMax = $afg
ReDim $aData[$iMax]
EndIf
$aData[$i][$j - 1] = $afg[$j]
Next
Next
ReDim $aData[$iMax]
Return $aData
EndFunc ;==>__IniReadToArray afan老师的心真宽广,热心、乐于助人的好人,好人一生平安!!再次谢谢老师不吝赐教、无私奉献! 大家快来分享afan老师提供的实用的函数吧,要吃水不忘挖井人,要感恩!
页:
[1]
2