ahmed9100 Posted September 14, 2013 Share Posted September 14, 2013 (edited) my unfinished code is #include <File.au3> Local $aRecords If Not _FileReadToArray(@ScriptDir&"\profile.rsc", $aRecords) Then MsgBox(4096, "Error", "Error file not found" & @error) else $line = "None" For $x = 1 To $aRecords[0] $result = StringInStr($aRecords[$x], "name") if $result = "0" Then Else MsgBox("","",$aRecords[$x]) $aArray1 = _StringBetween($aRecords[$x], 'name=', ' ') $line = $line &"|"& $aArray1[0] EndIf Next EndIf ;~ next save $line to setting file to put it in combo in the file i need to read : set [ find default=yes ] address-pool=dhcp_pool1 idle-timeout=10m name= default rate-limit=80K/800K shared-users=2 status-autorefresh=1m transparent-proxy=no add address-pool=dhcp_pool1 idle-timeout=10m keepalive-timeout=none name=30 rate-limit=64K/240K shared-users=1 status-autorefresh=1m transparent-proxy=no add address-pool=dhcp_pool1 idle-timeout=10m name=50 rate-limit=64K/400K shared-users=1 status-autorefresh=1m transparent-proxy=no add address-pool=dhcp_pool1 idle-timeout=10m name=100 rate-limit=64K/800K shared-users=1 status-autorefresh=1m transparent-proxy=no ------------------ word default and 30 and 50 and 100 only those words profile.rar Edited September 14, 2013 by ahmed9100 Link to comment Share on other sites More sharing options...
DW1 Posted September 14, 2013 Share Posted September 14, 2013 (edited) I'm no regex pro, but I would do it something like this: #include <array.au3> $sFileContents = FileRead(@ScriptDir & '\profile.rsc') Local $aArray, $aInt, $sString $aArray = StringRegExp($sFileContents, '\\[[:space:]]+(\S+.*?) rate', 3) If IsArray($aArray) Then $sString = $aArray[0] $aInt = StringRegExp($sFileContents, 'name=(.*?) ', 3) _ArrayDisplay($aInt, $sString) Edited September 14, 2013 by danwilli AutoIt3 Online Help Link to comment Share on other sites More sharing options...
ahmed9100 Posted September 14, 2013 Author Share Posted September 14, 2013 it work great but what if i need more like the file may content 2 or 3 or other number of string i need to get ? Link to comment Share on other sites More sharing options...
DW1 Posted September 14, 2013 Share Posted September 14, 2013 it work great but what if i need more like the file may content 2 or 3 or other number of string i need to get ? I went with what you gave me. Provide an example of a file with multiple strings to gather. AutoIt3 Online Help Link to comment Share on other sites More sharing options...
ahmed9100 Posted September 14, 2013 Author Share Posted September 14, 2013 example : 1 set [ find default=yes ] address-pool=dhcp_pool1 idle-timeout=10m name= default rate-limit=80K/800K shared-users=2 status-autorefresh=1m transparent-proxy=no add address-pool=dhcp_pool1 idle-timeout=10m keepalive-timeout=none name=normal rate-limit=64K/240K shared-users=1 status-autorefresh=1m add address-pool=dhcp_pool1 idle-timeout=10m keepalive-timeout=none name=30 rate-limit=64K/240K shared-users=1 status-autorefresh=1m transparent-proxy=no add address-pool=dhcp_pool1 idle-timeout=10m name=50 rate-limit=64K/400K shared-users=1 status-autorefresh=1m transparent-proxy=no add address-pool=dhcp_pool1 idle-timeout=10m name=100 rate-limit=64K/800K shared-users=1 status-autorefresh=1m transparent-proxy=no example : 2 set [ find default=yes ] address-pool=dhcp_pool1 idle-timeout=10m name= default rate-limit=80K/800K shared-users=2 status-autorefresh=1m transparent-proxy=no add address-pool=dhcp_pool1 idle-timeout=10m keepalive-timeout=none name=30 rate-limit=64K/240K shared-users=1 status-autorefresh=1m transparent-proxy=no add address-pool=dhcp_pool1 idle-timeout=10m name=50 rate-limit=64K/400K shared-users=1 status-autorefresh=1m transparent-proxy=no add address-pool=dhcp_pool1 idle-timeout=10m name=100 rate-limit=64K/800K shared-users=1 status-autorefresh=1m transparent-proxy=no add address-pool=dhcp_pool1 idle-timeout=10m name=400rate-limit=64K/800K shared-users=1 status-autorefresh=1m transparent-proxy=no i import this file from a server but it may have a multiple value or will be one the default i mean not exact number of profile your 2 StringRegExp solve this problem but i need it in one array and how to know array value count to read it in a loop to save if like default|30|50|100 to put it in a combobox sorry cuz im a beginner Link to comment Share on other sites More sharing options...
DW1 Posted September 14, 2013 Share Posted September 14, 2013 I'm not 100% sure I know what you are asking for, but perhaps this can get you started. Again, I'm no regex pro, so there may be way better ways to do this. #include <array.au3> $sFileContents = FileRead(@ScriptDir & '\profile.rsc') Local $aData $aData = StringRegExp($sFileContents, '(?m)(?:^[[:space:]]+|.*?name=)(\S+) (?:rate|.{0,2}$)', 3) _ArrayDisplay($aData) AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Solution DW1 Posted September 14, 2013 Solution Share Posted September 14, 2013 (edited) Or perhaps? #include <array.au3> $sFileContents = FileRead(@ScriptDir & '\profile.rsc') Local $aData, $sString $aData = StringRegExp($sFileContents, '(?m)(?:^[[:space:]]+|.*?name=)(\S+) (?:rate|.{0,2}$)', 3) $sString = _ArrayToString($aData) $sString = StringRegExpReplace($sString, '\|([a-z,A-Z])', '?$1') $aData = StringSplit($sString, '?') _ArrayDisplay($aData) Edited September 14, 2013 by danwilli AutoIt3 Online Help Link to comment Share on other sites More sharing options...
ahmed9100 Posted September 14, 2013 Author Share Posted September 14, 2013 Increasingly balanced you are a genies thx bro 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