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

## Recommended Posts

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

My recommended codes (that I worte):

_SharedVar - declare shared variables between 2 or more process directly on memory

CODENAME-SW_130416
If the English is not good in this post/code, please correct it (But do only PM).

##### Share on other sites

Would this do it?

```#include <string.au3>
#include <array.au3>

\$sItem = ">test1.com< a >test2.com< b >test3.com<"
\$itemList = _StringBetween(\$sItem, ">", "<")

_ArrayDisplay(\$itemList)```

The truth has been suppressed since the dawn of time.

##### Share on other sites

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

My recommended codes (that I worte):

_SharedVar - declare shared variables between 2 or more process directly on memory

CODENAME-SW_130416
If the English is not good in this post/code, please correct it (But do only PM).

##### 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)```
Edited by abberration

The truth has been suppressed since the dawn of time.

##### 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```

Sometimes I learn, Sometimes I teach...

AutoIt...

##### 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 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

My recommended codes (that I worte):

_SharedVar - declare shared variables between 2 or more process directly on memory

CODENAME-SW_130416
If the English is not good in this post/code, please correct it (But do only PM).

##### 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

Sometimes I learn, Sometimes I teach...

AutoIt...

##### Share on other sites

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

Sometimes I learn, Sometimes I teach...

AutoIt...

##### Share on other sites

oops

Edited by gil900

My recommended codes (that I worte):

_SharedVar - declare shared variables between 2 or more process directly on memory

CODENAME-SW_130416
If the English is not good in this post/code, please correct it (But do only PM).

##### Share on other sites

OK.

I am still determined to get on the problem.

I am going to solve the problem ..

`\$stop = False`

in the second loop

and changed the:

`If \$cbl = "<" Then`

to:

`If \$cbl = "<" and \$stop = False Then`

`\$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

My recommended codes (that I worte):

_SharedVar - declare shared variables between 2 or more process directly on memory

CODENAME-SW_130416
If the English is not good in this post/code, please correct it (But do only PM).

## Create an account

Register a new account