ElFarah Posted March 4, 2009 Share Posted March 4, 2009 I'm filling my ini file with two kinds of codes: ----- CODEFor $i=1 To 10 $PhoNum2c=GUICtrlRead($PhoNumInp2c[$i]) $PhoNam2c=GUICtrlRead($PhoNamInp2c[$i]) If StringLen($PhoNum2c)=9 Then If StringRegExp($PhoNum2c & "nothing", $IamPat, 0)=1 Then IniWrite($NewLstFile, "IAM", $PhoNum2c, '"' & $PhoNam2c & '"') ElseIf StringRegExp($PhoNum2c & "nothing", $MedPat, 0)=1 Then IniWrite($NewLstFile, "MEDITEL", $PhoNum2c, '"' & $PhoNam2c & '"') EndIf EndIf Next ------ CODE For $i=1 To UBound($iamnum) $t1="0" & $iamnum[$i-1] $t2='"IAM Contact ' & $i & '"' IniWrite($NewLstFile, "IAM", $t1, $t2) Next For $i=1 To UBound($mednum) $t1="0" & $mednum[$i-1] $t2='"MEDITEL Contact ' & $i & '"' IniWrite($NewLstFile, "Meditel", $t1, $t2) Next ------ both codes works fine, I have checked the ini file and found the expected results. But when I try to read all the keys created by the second code using IniReadSection function it reads only the values and ignores the keys. I have tried many tricks but with no success. The weird thing is that both files (1st filled wwith the 1st code and 2nd file filled with the 2nd code) are visually identical. I have attached an example of an ini file filled with the second code. You may execute the following code to see that it doesn't return the keys but only the values: CODE$var = IniReadSection("C:\TEST2.ini", "IAM") If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0][0] MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1]) Next EndIf Thank you in advance for your help.TEST2.zip Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 4, 2009 Moderators Share Posted March 4, 2009 ElFarah,Your ini files might look identical, but they are almost certainly not.If you look at the ini you posted with a hex editor, you have a "0x0d" at the end of each keyname (the telephone number) as you can see from this hex dump.000040 3d 30 32 3a 30 30 0d 0a 5b 49 41 4d 5d 0d 0a 30 36 38 33 34 31 32 33 39 0d 3d 22 49 41 4d 20 43 =02:00..[IAM]..068341239.="IAM C 000060 6f 6e 74 61 63 74 20 31 22 0d 0a 30 36 36 30 34 36 34 38 33 0d 3d 22 49 41 4d 20 43 6f 6e 74 61 ontact 1"..066046483.="IAM ContaThis is fooling IniSectionRead. Remove the "0x0d" and all is well!So your second code snippet is somehow adding this extra byte to the number - while your first snippet does not, as you say it works perfectly. Without the rest of your code I cannot say how the extra byte gets there, but it looks as if the array $iamnum elements already hold it.Hope this helps. Happy to probe further if you post enough code to let me do so.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ElFarah Posted March 4, 2009 Author Share Posted March 4, 2009 Thank you very much [Melba23], now I figured out the source of my problem. Here are the patterns: CODEGlobal $MedPat='(1[2479][0-9]{6}\D|4[459][0-9]{6}\D)|56[0-9]{6}\D|6[03459][0-9]{6}\D|7[459][0-9]{6}\D' ;Meditel nums pattern Global $IamPat='(1[013568][0-9]{6}\D|4[128][0-9]{6}\D)|5[0-589][0-9]{6}\D|6[12678][0-9]{6}\D|7[0-3678][0-9]{6}\D' ;IAM nums pattern ;those patterns match phone numbers in dfferents formats: +212xxxxxxxx or 00212xxxxxxxx or 212xxxxxxxx or 0xxxxxxxx or xxxxxxxx ;\D is added in order that the pattern won't match unexpected phone nums. Ex: without \D the 1st pattern would match in string like "21263265235Sara" two different phone numbers: 12632652 and 63265235, where as it has to match only the last one. ;I have added "nothing" to the source string (see 1st post) in order to match with \D the last phone number even if there are no other character next to it in the original source text. So now I figured out where the "0x0d" comes from, it comes from \D in the pattern. I find \D is necessary to not fall in the same problem as in the example above, however I'm falling in an other problem which is the extra "0x0d". So please can you help me rewriting the pattern or with an extra code snippet to remove "0x0d" from results? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 4, 2009 Moderators Share Posted March 4, 2009 ElFarah,I try to stay well away from StringRegExp unless absolutely necessary! I suggest you start a new thread with "RegExp Help" as the title - that always brings the gurus running!As a workaround - well, 0x0D is actually @CR, so after you have extracted the number you could run StringRegExpReplace($number, @CR, "") which will give you the number less the errant "0x0d".I have tested this suggestion with the following code and it seems to work:#include <Array.au3> $ini = "test.ini" $t1 = "012345678" & @CR IniWrite($ini, "TEST", $t1, "With @CR") $s1 = StringRegExpReplace($t1, @CR, "") IniWrite($ini, "TEST", $s1, "After SRE Replace") $array = IniReadSection($ini, "TEST") _ArrayDisplay($array)Interestingly, if you run the code again it keeps adding copies of the incorrect key=value to the .ini file, as it does not recognise the previous instances as valid key names.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ElFarah Posted March 4, 2009 Author Share Posted March 4, 2009 Thank you for the tips. Based on your suggestion I found an easy way to do the trick. Note that is not always an "0x0d", it could be any thing which comes next to the phone number. So here is the 2nd updated code snippet I'm using right now and works perfectly: CODE;[...] For $i=1 To UBound($iamnum) $iamnum[$i-1]=StringRegExpReplace($iamnum[$i-1], '\D', '') $t1="0" & $iamnum[$i-1] $t2='"' & 'IAM Contact ' & $i & '"' IniWrite($NewLstFile, "IAM", $t1, $t2) Next For $i=1 To UBound($mednum) $mednum[$i-1]=StringRegExpReplace($mednum[$i-1], '\D', '') $t1="0" & $mednum[$i-1] $t2='"' & 'MEDITEL Contact ' & $i & '"' IniWrite($NewLstFile, "Meditel", $t1, $t2) Next Thank you again for your help. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now