gempie Posted June 27, 2006 Share Posted June 27, 2006 Hi there, Need help on little issue, if i do: -------------------- $file = FileOpen("1.dcm", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop MsgBox(0, "Line read:", $line) Wend FileClose($file) ------------------------------------ Then it displays all the lines in the 1.dcm file. At one point i come across "patient name := xxx xxxxx" and "!patient ID := xxxx xxx" Know i want only these two lines to show in an msgbox. (the xxx info changes, the rest stays the same) i experimented a little with StringRegExp but can't figure it out. Thnx Link to comment Share on other sites More sharing options...
GaryFrost Posted June 27, 2006 Share Posted June 27, 2006 something like the following maybe: $file = FileOpen("1.dcm", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $save = "" ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop If StringInStr($line, "patient name :=") Or StringInStr($line, "!patient ID :=") Then $save = $save & $line & @CRLF WEnd FileClose($file) MsgBox(0, "Patient", $save) SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Ravenlark Posted June 27, 2006 Share Posted June 27, 2006 To clarify, is there only one pair of these results to display in the file? Are all results displayed in on msgbox, or is each pair of results displayed in a separate msgbox? Ravenlark-----------------------------------------------------when you find yourself with the majority, its time to pause and reflect - Mark Twain Link to comment Share on other sites More sharing options...
Xenobiologist Posted June 27, 2006 Share Posted June 27, 2006 HI, you can also try this: #include<Array.au3> #include <file.au3> Dim $aRecords If Not _FileReadToArray("1.dcm" ,$aRecords) Then MsgBox(4096,"Error", " Error reading file" & @error) Exit EndIf $aRecords = _ArrayToString($aRecords, chr(13)) $patient_Name_A = _SRE_Between($aRecords, 'patient name :="', '"', 1); change END = '"' to your needs $patient_ID_A = _SRE_Between($aRecords, '!patient ID :="', '"', 1); change END = '"' to your needs _ArrayDisplay($patient_Name_A, "Name") _ArrayDisplay($patient_ID_A, "ID") Func _SRE_Between($s_String, $s_Start, $s_End, $i_ReturnArray = 0); $i_ReturnArray returns an array of all found if it = 1, otherwise default returns first found $a_Array = StringRegExp($s_String, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3) If Not @error And Not $i_ReturnArray And IsArray($a_Array) Then Return $a_Array[0] If IsArray($a_Array) Then Return $a_Array EndFunc So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
gempie Posted June 28, 2006 Author Share Posted June 28, 2006 Thanx alot everybody, Gafrost, your script works like a charm Th. Meger, i ám intressted in ur aproach aswel but it doesn.t seem to work. (am using beta .127) it does't give an error but it doens't display anything aswell. Gempie Link to comment Share on other sites More sharing options...
Xenobiologist Posted June 28, 2006 Share Posted June 28, 2006 (edited) Thanx alot everybody,Gafrost, your script works like a charm Th. Meger, i ám intressted in ur aproach aswel but it doesn.t seem to work. (am using beta .127) it does't give an error but it doens't display anything aswell.GempieHi,you have to change these lines$aRecords = _ArrayToString($aRecords, chr(13))$patient_Name_A = _SRE_Between($aRecords, 'patient name :="', '"', 1); change END = '"' to your needs$patient_ID_A = _SRE_Between($aRecords, '!patient ID :="', '"', 1); change END = '"' to your needsThe script reads the file into an array. Each element of the array is delimeted by CR which is chr(13).Then I fill the array $patient_Name_A with everything found between patient name :=" and ". Maybe the is no string between that in your file. (or only ones)If you can upload a sample of the file 1.dcm, I can fix that to your needs. Otherwise just use Gary's version. So long,Mega Edited June 28, 2006 by th.meger Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 28, 2006 Moderators Share Posted June 28, 2006 (edited) Hey, _SRE_Between() looks familiar Edit: I imagine this would be quicker:#include<Array.au3> Dim $aRecords = '1.dcm' $patient_Name_A = _SRE_Between($aRecords, 'patient name :="', '"'); change END = '"' to your needs $patient_ID_A = _SRE_Between($aRecords, '!patient ID :="', '"'); change END = '"' to your needs _ArrayDisplay($patient_Name_A, "Name") _ArrayDisplay($patient_ID_A, "ID") Func _SRE_Between($s_File, $s_Start, $s_End) $aFRead = FileRead($s_File, FileGetSize($s_File)) $a_Array = StringRegExp($aFRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3) If IsArray($a_Array) Then Return $a_Array EndFuncNo need to do FileReadToArray() with StringRegExp() if your going to return the array you want anyway. Edited June 28, 2006 by SmOke_N 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...
Xenobiologist Posted June 28, 2006 Share Posted June 28, 2006 Hey, _SRE_Between() looks familiar Hi SmOke_N, looks familiar maybe because you wrote it. I love that func and use it quite very often. (may I say that this way in English?) So long, Mega PS: Hope it helps him out. Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times 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