Guest Posted August 15, 2012 Share Posted August 15, 2012 (edited) Need someone to check what is wrong in the code .. I made an half of the algorithm that knows how to Extract a URL "> <". Located between the symbols ">" and "<" I know it's not enough but said it was only half (actually less than a quarter) of the algorithm. In the following example test: >test1.com< a >test2.com< b >test3.com< We have three sites within these signs. Code should open a msgbox 3 times. Each msgbox displayed a different site. In this case it should be like this: msgbox 1 shows - "test1.com" msgbox 2 shows - "test2.com" msgbox 3 shows - "test3.com" And so on. This algorithm (I was working on four days) can do that. But there is a problem. For some reason, the algorithm also shows me a message mor msgboxses With other unwanted additions .. This is my code: expandcollapse popup$file = "test.txt" $after_letter = ">test1.com< a >test2.com< b >test3.com< " $al = "" for $m = 1 to 300 step 1 $after_letter_c = StringTrimRight($after_letter, $m) if $after_letter_c = "" Then $an = $m ExitLoop EndIf Next for $m2 = 1 to $an step 1 $vm = StringTrimRight($after_letter, $an-$m2) $vm = StringTrimLeft($vm, $m2-1) if1() Next Func if1() If $vm = "." Then $al_b = StringTrimLeft($after_letter, $m2-2) $nal = $an-$m2+2 $al = StringTrimRight($al_b, $nal-1) $bl_0 = StringTrimLeft($al_b, 2) $bl = StringTrimRight($bl_0, $nal-3) If $al <> " " And $bl <> " " Then $nal_b = $nal-2 For $g = 1 to $nal-2 step 1 $cbl_0 = StringTrimLeft($bl_0,$g-1) $cbl = StringTrimRight($cbl_0,$nal_b-$g) If $cbl = "<" Then $nal_c = $nal_b-($g-1) $cbl_1 = StringTrimRight($after_letter,$nal_c) $nal_d = $an-$nal_c For $e = 1 to $nal_d step 1 $cbl_0a = StringTrimLeft($cbl_1,$nal_d-$e) If StringLeft($cbl_0a,1) = ">" Then $final = StringTrimLeft($cbl_0a,1) MsgBox(4096,"test",$final) EndIf Next EndIf Next Else MsgBox(4096,"working_case2","ContinueChack the next if") EndIf EndIf EndFunc I do not know many shortcuts so I just build it my own .. But please do not bring me a shortcut code and go. I worked on it a long time and I want to understand what is wrong in my code. Edited August 15, 2012 by Guest Link to comment Share on other sites More sharing options...
abberration Posted August 15, 2012 Share Posted August 15, 2012 Would this do it? #include <string.au3> #include <array.au3> $sItem = ">test1.com< a >test2.com< b >test3.com<" $itemList = _StringBetween($sItem, ">", "<") _ArrayDisplay($itemList) Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
Guest Posted August 15, 2012 Share Posted August 15, 2012 (edited) Would this do it? #include <string.au3> #include <array.au3> $sItem = ">test1.com< a >test2.com< b >test3.com<" $itemList = _StringBetween($sItem, ">", "<") _ArrayDisplay($itemList) Yes but the way the algorithm searches for the site is very important For my overall goal(this is very sample test) . I'll describe the way it works: 1) The algorithm scans the entire line. 2) the algorithm searches for any "." in the Line. 3) The algorithm checks before and after the sign "." if There is no space. (" ") 4) If before and after the sign "." . There is no space, The algorithm will assume that the mark "." Located within in some URL. 5) by means of mathematics, the algorithm begins to search before this mark ('.') for the sign ">". Immediately after this, the algorithm searching for the sign ">" in the opposite direction from that point. 6) Based on the information collected and calculated, the algorithm can give only the URL. The reason it has to look that way is because of the fact that it's not supposed to know what it is looking for. In Test I showed, it is very easy to be clever and make shortcuts. But in reality it will not be like that. There are lots of options .. Edited August 15, 2012 by Guest Link to comment Share on other sites More sharing options...
abberration Posted August 15, 2012 Share Posted August 15, 2012 (edited) If you are trying to make sure that it's actually a website, then you could do it with my code below. It checks inside the > and < for a string. Then it splits the string by ".". It takes the last section (the .com part) and checks to see if it is "com". If it is, it adds that website to a new array. As you can see in my example string, I have a string "not a website" and "domain.org" are ignored. However, it does include www.onelastwebsite.com.#include <string.au3> #include <array.au3> $sItem = ">test1.com< a >test2.com< b >test3.com< c >not a website> < d >domain.org< e >www.onelastwebsite.com<" $itemList = _StringBetween($sItem, ">", "<") Dim $finalItemArray[1] $j = 0 For $i = 1 to UBound($itemList) Step 1 $testString = StringSplit($itemList[$i-1], ".") If NOT @error Then $testStringLastPos = $testString[0] If $testString[$testStringLastPos] = "com" Then $finalItemArray[$j] = $itemList[$i-1] $j += 1 ReDim $finalItemArray[$j+1] EndIf EndIf Next _ArrayDisplay($finalItemArray) Edited August 15, 2012 by abberration Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
Danyfirex Posted August 15, 2012 Share Posted August 15, 2012 Maybe this can help Local $nOffset = 1 $after_letter = ">test1.com< a >test2.com< b >test3.com< " Local $array While 1 $array = StringRegExp($after_letter, '(?i)>(.*?)<(?i)', 1, $nOffset) If @error = 0 Then $nOffset = @extended Else ExitLoop EndIf For $i = 0 To UBound($array) - 1 MsgBox(0, "RegExp Test with Option 1 - " & $i, $array[$i]) Next WEnd Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
BrewManNH Posted August 15, 2012 Share Posted August 15, 2012 $array = StringRegExp($after_letter, '(?i)>(.*?)<(?i)', 1, $nOffset) An even shorter regex could do away with the (?i) at the beginning and end of the above code, it's not necessary to disable case sensitivity because you're not actually looking for any specific characters, you're just looking for anything that's in between the brackets regardless of whether it's an upper case or lower case letter, or even a number. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Guest Posted August 15, 2012 Share Posted August 15, 2012 If you are trying to make sure that it's actually a website, then you could do it with my code below. It checks inside the > and < for a string. Then it splits the string by ".". It takes the last section (the .com part) and checks to see if it is "com". If it is, it adds that website to a new array. As you can see in my example string, I have a string "not a website" and "domain.org" are ignored. However, it does include www.onelastwebsite.com. #include <string.au3> #include <array.au3> $sItem = ">test1.com< a >test2.com< b >test3.com< c >not a website> < d >domain.org< e >www.onelastwebsite.com<" $itemList = _StringBetween($sItem, ">", "<") Dim $finalItemArray[1] $j = 0 For $i = 1 to UBound($itemList) Step 1 $testString = StringSplit($itemList[$i-1], ".") If NOT @error Then $testStringLastPos = $testString[0] If $testString[$testStringLastPos] = "com" Then $finalItemArray[$j] = $itemList[$i-1] $j += 1 ReDim $finalItemArray[$j+1] EndIf EndIf Next _ArrayDisplay($finalItemArray) thanks but it is fail witch: test2.com/test Link to comment Share on other sites More sharing options...
guinness Posted August 15, 2012 Share Posted August 15, 2012 They could also use V instead of a greedy dot. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Danyfirex Posted August 15, 2012 Share Posted August 15, 2012 $array = StringRegExp($after_letter, '(?i)>(.*?)<(?i)', 1, $nOffset) An even shorter regex could do away with the (?i) at the beginning and end of the above code, it's not necessary to disable case sensitivity because you're not actually looking for any specific characters, you're just looking for anything that's in between the brackets regardless of whether it's an upper case or lower case letter, or even a number. ups :S sorry BrewManNH I don't have experience using StringRegExp. Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
guinness Posted August 15, 2012 Share Posted August 15, 2012 Now is the time to learn. How did you come up with the code above if you have limited knowledge? UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Danyfirex Posted August 15, 2012 Share Posted August 15, 2012 (edited) Now is the time to learn. How did you come up with the code above if you have limited knowledge? I look the help example $array = StringRegExp('<test>a</test> <test>b</test> <test>c</Test>', '<(?i)test>(.*?)</(?i)test>', 1, $nOffset) and I modificated it. Edited August 15, 2012 by Danyfirex Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
guinness Posted August 15, 2012 Share Posted August 15, 2012 OK. That's a point I should update those examples to meet the AutoIt standards of today. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Guest Posted August 15, 2012 Share Posted August 15, 2012 (edited) oops Edited August 15, 2012 by Guest Link to comment Share on other sites More sharing options...
Guest Posted August 15, 2012 Share Posted August 15, 2012 (edited) OK. I am still determined to get on the problem. I am going to solve the problem .. i Adde the line: $stop = False in the second loop and changed the: If $cbl = "<" Then to: If $cbl = "<" and $stop = False Then and added the line $stop = True in If $cbl = "<" And $stop = False Now it seems I solved many problems. But there is still another case. I think I will understand this alone Edited August 15, 2012 by Guest 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