找回密码
 加入
搜索
查看: 14609|回复: 31

[系统综合] 如何判定ini中不同字段名中关键值是否达到指定数量

 火.. [复制链接]
发表于 2014-9-27 09:58:49 | 显示全部楼层 |阅读模式
ini配置
[12]
aa=123
bb=1
[22]
aa=123
bb=1
[a1]
aa=123
bb=2

求教,例:ini字段名都不同,我如何判断关键字bb中1有2个的话则自动判断2是否有2个,依次类推!
如果判定小于2个的话则写入一个
[34]
aa=123
bb=1;这个数值1,是判断过后小于2个的那个数值!
发表于 2014-9-27 15:50:02 | 显示全部楼层
回复 1# abcd1234
$aStr = StringRegExp(FileRead('your.ini'), '(?m)^bb=1[\r\n]', 3)
If Not @error Then MsgBox(0, '匹配数量', UBound($aStr))
 楼主| 发表于 2014-9-28 08:15:07 | 显示全部楼层
回复 2# user3000


    那怎么给这段赋予循环判断呢,如果 bb=1 ,这个匹配等于3个的话,bb=1就自动加1,也就是bb=2,继续匹配,依次类推! 如果bb=1 (1这个数值是根据匹配小于3的数值,也包括bb=2;b=3.....)匹配小于3个的话,就弹出信息框!
 楼主| 发表于 2014-9-29 10:25:32 | 显示全部楼层
兄弟们,帮帮忙!~~~~
发表于 2014-9-30 05:43:47 | 显示全部楼层
本帖最后由 dunphy 于 2014-11-5 03:02 编辑

回复 4# abcd1234


    举个批例子也不说清楚。
给你段代码,你看是不是这个意思。若字段里的BB值为1连续出现2个。则BB的值+1,  ,再接着判断字段里BB值为2的情况,若有2个,BB值再加1 .是不是这个意思。。


#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
Global Const $gc_formName = "配置文件"
Global $ini = @ScriptDir & "\*.ini"
Global $a_PznameA = "aa", $a_PznameB = "bb"
#Region
Global $gu_PzForm = GUICreate($gc_formName, 402, 288, 340, 128)
Global $gu_PzGroup1 = GUICtrlCreateGroup("[1]配置文件", 13, 6, 374, 60)
Global $gu_PzInput1 = GUICtrlCreateInput("", 25, 32, 260, 21)
GUICtrlSetData($gu_PzInput1, $ini)
Global $gu_PzButton1 = GUICtrlCreateButton("随机写入(O)", 288, 30, 86, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $gu_PzButton2 = GUICtrlCreateButton("关于(A)", 13, 250, 59, 25)
Global $gu_PzButton3 = GUICtrlCreateButton("输出", 264, 250, 59, 25)
Global $gu_PzButton4 = GUICtrlCreateButton("退出(X)", 328, 250, 59, 25)
GUISetState(@SW_SHOW)
#EndRegion
_Main() ;主函数开始
Exit

Func _Main()
        
Local $nMsg
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $gu_PzButton1

                        Local $path = FileSaveDialog("配置文件存储位置", _
                                        @ScriptDir, "配置文件.ini (*.ini)|所有文件(*.*)", 1 + 8, _
                                        "*.ini", $gu_PzForm)
                        If @error Then                 
                                MsgBox(16, "提示", "你未选择INI文件.")
                        
                        Else
                                If FileExists( $path) = 1 Then FileDelete( $path)
                                Local $a_SectionName[5001]
                                
                                Local $i, $b = UBound($a_SectionName)
                                For $i = 1 To $b - 1 Step 1
                                        ;;$a_SectionName[0] = UBound($a_SectionName) - 1
                                        $a_SectionName[$i] = "a" & $i
                                        IniWrite( $path, $a_SectionName[$i], $a_PznameA, 123)
                                        IniWrite( $path, $a_SectionName[$i], $a_PznameB, 1)
                                Next
                                GUICtrlSetData($gu_PzInput1, $path)
                                MsgBox(0, "提示:", "成功写入配置文件" & @CRLF & "请在当前程序目录查看")
                        EndIf
                Case $gu_PzButton3
                        Local  $path = GUICtrlRead($gu_PzInput1)
                        Global $sSection = IniReadSectionNames( $path)
                        ;;        _ArrayDisplay($sSection, "$sSection")
                        If @error Then
                                MsgBox(0, "提示", "请先创建后再输出查看")
                                ExitLoop
                        EndIf
                        Global $ArraySecName[5001][5]
                        For $i = 1 To UBound($ArraySecName) - 1

                                Local $pz_array = IniReadSection( $path, $sSection[$i])
                                $ArraySecName[0][0] = "字段名"
                                $ArraySecName[0][1] = "第一关键字"
                                $ArraySecName[0][2] = "第一关键字的值"
                                $ArraySecName[0][3] = "第二关键字"
                                $ArraySecName[0][4] = "第二关键字的值"

                                $ArraySecName[$i][0] = $sSection[$i]
                                $ArraySecName[$i][1] = $pz_array[1][0]
                                $ArraySecName[$i][2] = $pz_array[1][1]
                                $ArraySecName[$i][3] = $pz_array[2][0]
                                $ArraySecName[$i][4] = $pz_array[2][1]
                                ;If $ArraySecName[$I][4] = 1 Then
                                ;MsgBox (0,"提示","字段"& $sSection[$I]&"中关健字bb值为1")
                                ;EndIf
                        Next
                        _ArrayDisplay($ArraySecName, "$Array")
                        ;;_Exists()                        ;如果连续二个的BB值为1,则数组中追加一字段
                        

                Case $gu_PzButton2
                        MsgBox(0 + 64, $gc_formName, "作者:#####")

                Case $gu_PzButton4
                        Exit
        EndSwitch
WEnd

EndFunc   ;==>_main
发表于 2014-10-5 06:29:28 | 显示全部楼层
看不懂。。。。
发表于 2014-10-6 15:55:58 | 显示全部楼层
前来学习。。。。。。。。。。。。。。。。。。。。。。
发表于 2014-10-7 14:41:01 | 显示全部楼层
本帖最后由 dunphy 于 2014-10-7 14:42 编辑

回复 6# netegg


    前辈看不懂是不是因为他提的问题不具体???我感觉他的意思如同我现在创建的INI的代码,如果字段里有2个BB值为1,那么重新写入一个字段
[11]
AA=123
BB=2
然后再继续匹配,如果再往下,还有2个BB值为1
再重新写入一个字段
【X1】
AA=123
BB=2

判断完后,现在的新数组里如果匹配AA=2的次数小于3个的话MSGBOX提示一下

再载入新的数组,判断是否有2个BB值为2的情况,
如果有再写入BB=3
然后再枚举下去。。。
 楼主| 发表于 2014-10-23 22:41:19 | 显示全部楼层
回复 8# dunphy


    能否直接判断后输出为ini,帮下忙
发表于 2014-10-25 21:21:59 | 显示全部楼层
回复 6# netegg


    蛋蛋,帮着解决一下这个嘛,数组都列出来了。好像LZ是这个意思。现在有100个BB=1,

1. 从第一个元互索引开始判断,如果连续有3个BB=1 ,重新向另外一个新数组写一行并建赋值BB为2,并从现数组第4个元素索引继续判断至完......(如果小于3个BB=1的话信息提示).

2 .接着判断BB为2的情况

3,接着判断BB为3的情况
4.. 依次至完
发表于 2014-10-28 10:50:06 | 显示全部楼层
整到数组里做,不是很简单嘛,dunphy,你不会这也想不到吧
发表于 2014-10-28 11:08:48 | 显示全部楼层
理解上好像不是,好像是[1]的一个项是[2],然后类推的意思
发表于 2014-10-28 11:16:10 | 显示全部楼层
回复 10# dunphy
问的太笼统了点
发表于 2014-10-29 15:59:17 | 显示全部楼层
回复 11# netegg


    不是已经整到数组里面了的嘛 ,见5楼 ,只是如何来判定,如果有三个BB=1就重新定义数组。加个BB=2.如果小于3个就提示,然后再接着判定加到数组后面的BB=2的情况,如果BB=2的元素个数超过三个,就重新定义数组。向数组里写入BB=3。小于三个再提示。依次类推.比如BB=1的元素个数为16,BB=2的元素个数等于16/3 约等于5个,还有一个就提示,BB=3的情况就5/3 约等于1个,还有的就提示。我理解的LZ要表达的就是这个意思。
发表于 2014-10-29 21:43:03 | 显示全部楼层
回复 14# dunphy
类似传递,或者是调用个自定义函数
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-2 13:12 , Processed in 0.079251 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表