Sign in to follow this  
Followers 0
gil900

Need someone genius to check what is wrong in my search code ..

14 posts in this topic

#1 ·  Posted (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:

$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 by gil900

Share this post


Link to post
Share on other sites



#3 ·  Posted (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 by gil900

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by abberration

RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

$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 Gude
How 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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

They could also use V instead of a greedy dot.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

$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.

Share this post


Link to post
Share on other sites

Now is the time to learn. How did you come up with the code above if you have limited knowledge?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#11 ·  Posted (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 by Danyfirex

Share this post


Link to post
Share on other sites

OK. That's a point I should update those examples to meet the AutoIt standards of today.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Share this post


Link to post
Share on other sites

#14 ·  Posted (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 by gil900

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0