Noobster24 Posted June 20, 2006 Share Posted June 20, 2006 Hi,my program creates a txt-file with info from a website, sometimes there is '&' (HTML &), now i want to replace this '&'...This is the function to pick the names and id's from the txt-file:Func _SRE_Between($s_FilePath, $s_Start, $s_End) $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath)) $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3) If Not @error Then Return $a_Array EndFuncI thought that I could do it like this:Func _SRE_Between($s_FilePath, $s_Start, $s_End) $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath)) $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3) $a_Array = StringRegExpReplace($a_Array, '(?:&)', '&') If Not @error Then Return $a_Array EndFuncBut that isn't working, what's the right pattern? (Yes, I have read this article: http://www.autoitscript.com/forum/index.ph...l=stringregexp) Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc. Link to comment Share on other sites More sharing options...
seandisanti Posted June 20, 2006 Share Posted June 20, 2006 Hi, my program creates a txt-file with info from a website, sometimes there is '&' (HTML &), now i want to replace this '&'... This is the function to pick the names and id's from the txt-file: Func _SRE_Between($s_FilePath, $s_Start, $s_End) $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath)) $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3) If Not @error Then Return $a_Array EndFunc I thought that I could do it like this: Func _SRE_Between($s_FilePath, $s_Start, $s_End) $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath)) $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3) $a_Array = StringRegExpReplace($a_Array, '(?:&)', '&') If Not @error Then Return $a_Array EndFunc But that isn't working, what's the right pattern? (Yes, I have read this article: http://www.autoitscript.com/forum/index.ph...l=stringregexp) could you post a sampling of the data to be parsed? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 20, 2006 Moderators Share Posted June 20, 2006 (edited) If the 2nd $a_Array = is an array you aren't using it as an array but a only as a string, if it isn't an $a_Array then the string returned would be blank anyway.$s = 'this is a test & only a test' $Test = _SRE_Between($s, 'this', 'only') If IsArray($Test) Then For $i = 0 To UBound($Test) - 1 MsgBox(0,'info', $Test[$i]) Next EndIf Func _SRE_Between($s_FilePath, $s_Start, $s_End) ;Local $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath)) Local $h_FRead = $s_FilePath Local $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3) If IsArray($a_Array) And Not @error Then For $iCount = 0 To UBound($a_Array) - 1 $a_Array[$iCount] = StringRegExpReplace($a_Array[$iCount], '(?:&)', '&') Next Return $a_Array EndIf Return 0 EndFunc Edit: And now that I "really" look at it, this would be much faster I'm sure:$s = 'this is a test & only a test' $Test = _SRE_Between($s, 'this', 'only') If IsArray($Test) Then For $i = 0 To UBound($Test) - 1 MsgBox(0,'info', $Test[$i]) Next EndIf Func _SRE_Between($s_FilePath, $s_Start, $s_End) ;Local $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath)) Local $h_FRead = $s_FilePath $sReplace = StringRegExpReplace($h_FRead, '(?:&)', '&') Local $a_Array = StringRegExp($sReplace, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3) If IsArray($a_Array) And Not @error Then Return $a_Array Return 0 EndFunc Edited June 20, 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...
Noobster24 Posted June 20, 2006 Author Share Posted June 20, 2006 If the 2nd $a_Array = is an array you aren't using it as an array but a only as a string, if it isn't an $a_Array then the string returned would be blank anyway.$s = 'this is a test & only a test' $Test = _SRE_Between($s, 'this', 'only') If IsArray($Test) Then For $i = 0 To UBound($Test) - 1 MsgBox(0,'info', $Test[$i]) Next EndIf Func _SRE_Between($s_FilePath, $s_Start, $s_End) ;Local $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath)) Local $h_FRead = $s_FilePath Local $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3) If IsArray($a_Array) And Not @error Then For $iCount = 0 To UBound($a_Array) - 1 $a_Array[$iCount] = StringRegExpReplace($a_Array[$iCount], '(?:&)', '&') Next Return $a_Array EndIf Return 0 EndFunc Edit: And now that I "really" look at it, this would be much faster I'm sure:$s = 'this is a test & only a test' $Test = _SRE_Between($s, 'this', 'only') If IsArray($Test) Then For $i = 0 To UBound($Test) - 1 MsgBox(0,'info', $Test[$i]) Next EndIf Func _SRE_Between($s_FilePath, $s_Start, $s_End) ;Local $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath)) Local $h_FRead = $s_FilePath $sReplace = StringRegExpReplace($h_FRead, '(?:&)', '&') Local $a_Array = StringRegExp($sReplace, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3) If IsArray($a_Array) And Not @error Then Return $a_Array Return 0 EndFunc Damn, that looks complicated, i'll taak a look at that later, must go now, thank you all Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc. 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