Moderators SmOke_N Posted July 30, 2011 Moderators Share Posted July 30, 2011 Your expression pattern is... well, it's not right.Your example also will fail or return bad data if that section doesn't have the "key" but a later section does.Global $gs_Ini = "" $gs_Ini &= "[Section1]" & @CRLF $gs_Ini &= "RandomKey=Apple" & @CRLF $gs_Ini &= "[Section2]" & @CRLF $gs_Ini &= "DontReadThisKeyInThisKey=Opps Failure!" & @CRLF Global $gs_ReturnData = _IniString_Read($gs_Ini, "Section1", "DontReadThisKeyInThisKey") ConsoleWrite($gs_ReturnData & @CRLF) Func _IniString_Read($sIni, $sSection, $sKey, $sDefault = "") ;by Arcker ; On 08/04/2011 ; Only one regexp to get the value ! ; execution < 1 ms Local $sSect = StringRegExp($sIni, "(?i)(?s)(?m)(?:.*)(\["& $sSection &"\].*?^"&$sKey&"=)(.+?$)",1) ; Get entire $sSection section as string. If @error Then Return $sDefault Else Return StringStripCR($sSect[1]) EndIf EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
arcker Posted August 1, 2011 Share Posted August 1, 2011 mmm didn't think about it, the "cross-section" value. Will try to add some check. For the pattern, what is "not right" ? I've just started to use pattern so i've to learn a lot. -- Arck System _ Soon -- Ideas make everything "La critique est facile, l'art est difficile" Projects :[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list] Link to comment Share on other sites More sharing options...
arcker Posted August 1, 2011 Share Posted August 1, 2011 corrected version, but doesn't support if a section is commented out between two sections. need to escape lines beginning with # Global $gs_Ini = "" $gs_Ini &= "[Section1]" & @CRLF $gs_Ini &= "RandomKey=Apple" & @CRLF $gs_Ini &= "[Section2]" & @CRLF $gs_Ini &= "DontReadThisKeyInThisKey=Failure" & @CRLF $gs_Ini &= "#[Section3]" & @CRLF $gs_Ini &= "DontReadThisKeyInThisKeyPlz=I do what I want" & @CRLF $gs_Ini &= "[Section4]" & @CRLF $gs_Ini &= "DontReadThisKeyInThisKeyPlz=Failure 3" & @CRLF Global $gs_ReturnData = _IniString_Read($gs_Ini, "Section1", "RandomKey") ConsoleWrite($gs_ReturnData & @CRLF) Global $gs_ReturnData = _IniString_Read($gs_Ini, "Section1", "DontReadThisKeyInThisKey") ConsoleWrite($gs_ReturnData & @CRLF) Global $gs_ReturnData = _IniString_Read($gs_Ini, "Section3", "DontReadThisKeyInThisKeyPlz") ConsoleWrite($gs_ReturnData & @CRLF) Func _IniString_Read($sIni, $sSection, $sKey, $sDefault = "") ;by Arcker ; On 08/04/2011 ; Only one regexp to get the value ! ; execution < 1 ms Local $sSect = StringRegExp($sIni, "(?i)(?s)(?m)(?:.*)(\["& $sSection &"\].[^\[]*?"&$sKey&"=)(.+?$)",1) ; Get entire $sSection section as string. If @error Then Return $sDefault Else Return StringStripCR($sSect[1]) EndIf EndFunc -- Arck System _ Soon -- Ideas make everything "La critique est facile, l'art est difficile" Projects :[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list] Link to comment Share on other sites More sharing options...
lowray1975 Posted October 11, 2012 Share Posted October 11, 2012 (edited) I believe I've found a bug. For the key named "DownloadURL32" the UDF will match the "DownloadURL32", "URL32" and "32" (well, the UDF will match string of characters right to left). I'll post the fix if I'm successful [RemoteSupport] DownloadURL32=1234 $INI_RemoteSupport_DownloadURL32 = _IniString_Read($tmpGuardianINI, "RemoteSupport", "DownloadURL32", "") $INI_RemoteSupport_DownloadURL32 = _IniString_Read($tmpGuardianINI, "RemoteSupport", "URL32", "") $INI_RemoteSupport_DownloadURL32 = _IniString_Read($tmpGuardianINI, "RemoteSupport", "32", "") All return the value "1234" Edited October 11, 2012 by lowray1975 Link to comment Share on other sites More sharing options...
stamandster Posted October 17, 2012 Share Posted October 17, 2012 I'm really interested in this UDF but I'm loosing alot (about 25%) of data for some reason. It's also slower than using INIRead (which reads the INI file everytime). I would think it'd be faster? Link to comment Share on other sites More sharing options...
x_bennY Posted June 10, 2018 Share Posted June 10, 2018 Why this is slower than IniRead? It gets slower according to the amount of data, IniRead dosen't seem to be affected. 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