Sign in to follow this  
Followers 0
czardas

Modal String Search & Selective Filtering.

4 posts in this topic

#1 ·  Posted (edited)

I would like to search a string which loops back on itself. For example searching for 'EAB' in the string 'ABCDE' would return 'ABCDE', but 'ACD' would return nothing. One way would be to extend the string's length. like this: 'ABCDEABCDE'. However this is a tedious operation when you want to search hundereds of strings in the same way.

Another puzzle to me is the following: How to ignore certain elements within a string whilst searching for a match. For example:

Search for 1's found at the following locations: 1011. Filter out results where 1 appears at any other location.

Search the following strings:

1000, 0010, 0001, 1010, 1001 and 1011 would all return a positive result, because the 1's in the string all occur at the locations asked for in the search criteria.

1111, 1110, 1100, 1101, 0100, 0110 and 0111 would all return nothing, because the second digit in each string is 1, which is not allowed.

0000 would return nothing, because it doesn't contain any 1's at all. Get it?

That is not the whole story. I wish to combine the two ideas, for example:

Treat the following string as being modal: 10111

Search for two 1's separated by a single digit. (101 or 111)

3 Results found:

10111

10111

10111

Now that I have tried to explain what I want to do, I would like to know if there is a simple way to do this? This is for the analysis of musical scales.

Edited by czardas

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Maybe you could use,

StringInStr ( "string", "substring" [, casesense [, occurrence]] )

Checks if a string contains a given substring.

Just add some scripting after it and you got yourself a nice search function..

Edited by logi

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Here's a solution: It works with both letters and numbers. I've spent quite some time getting this right (50 min.). I hope this is what you were looking for. The pattern can be changed from 11 to 101 or 1011. Just ask.

Dim $searchfor = "B"
Dim $searchstring[7] = ["ABCDE", "BABCD", "BACBA", "ABCBD", "DABCB", "DBACB", "ABBDC"]oÝ÷ Ù«­¢+Ù¥´ÀÌØíÍÉ¡½ÈôÅÕ½ÐìÄÅÕ½Ðì)¥´ÀÌØíÍÉ¡ÍÑÉ¥¹lÝtôlÅÕ½ÐìÀÀÀÀÀÅÕ½Ðì°ÅÕ½ÐìÄÀÄÀÀÅÕ½Ðì°ÅÕ½ÐìÄÀÀÄÀÅÕ½Ðì°ÅÕ½ÐìÀÄÀÄÀÅÕ½Ðì°ÅÕ½ÐìÀÀÄÀÄÅÕ½Ðì°ÅÕ½ÐìÀÄÀÀÄÅÕ½Ðì°ÅÕ½ÐìÀÄÄÀÀÅÕ½Ðít()½ÈÀÌØíàôÀѼØ(%5Í ½à À°ÀÌØíÍÉ¡ÍÑÉ¥¹lÀÌØíát°5½±¥±ÑÈ ÀÌØíÍÉ¡ÍÑÉ¥¹lÀÌØíát°ÀÌØíÍÉ¡½È¤¤)9áÐ()Õ¹5½±¥±ÑÈ ÀÌØíÍÑÉ¥¹}ѽ}ÍÉ °ÀÌØíÍÉ¡}½È¤($ÀÌØíÍÑÉ¥¹}ѽ}ÍÉ µÀìôÀÌØíÍÑÉ¥¹}ѽ}ÍÉ (%½ÈÀÌØíàôÀѼMÑÉ¥¹1¸ ÀÌØíÍÑÉ¥¹}ѽ}ÍÉ ¤´Ä($%%MÑÉ¥¹1Ð ÀÌØíÍÑÉ¥¹}ѽ}ÍÉ °Ä¤ôôÀÌØíÍÉ¡}½ÈQ¡¸($$%%MÑÉ¥¹5¥ ÀÌØíÍÑÉ¥¹}ѽ}ÍÉ °Ì°Ä¤ôôÀÌØíÍÉ¡}½ÈQ¡¸ìÌ¥¸Ñ¡¥Ì±¥¹µ¹ÌÑ¡ÍÉ¡ÉÑÈɽ´Ñ¡ÕÉɹеÕÍи¸ÀÌØíÍÉ¡}½È¸($$$%IÑÕɸÄ($$%¹%($%¹%($$ÀÌØíÍÑÉ¥¹}ѽ}ÍÉ ôMÑÉ¥¹QÉ¥µ1Ð ÀÌØíÍÑÉ¥¹}ѽ}ÍÉ °Ä¤(%9áÐ(%IÑÕɸÀ)¹Õ¹
Edited by Manadar

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Dim $searchfor = "1"
Dim $searchstring[7] = ["00000", "10100", "10010", "01010", "00101", "01001", "01100"]

For $x = 0 to 6
    MsgBox(0, $searchstring[$x], ModalFilter($searchstring[$x],$searchfor))
Next

Func ModalFilter($string_to_search, $search_for)
    $string_to_search &= $string_to_search
    For $x = 0 to StringLen($string_to_search)-1
        If StringLeft($string_to_search,1) == $search_for Then
            If StringMid($string_to_search,3,1) == $search_for Then ;3 in this line means the 3rd character from the current must be .. $search_for.
                Return 1
            EndIf
        EndIf
        $string_to_search = StringTrimLeft($string_to_search,1)
    Next
    Return 0
EndFunc
Manadar; thanks for investing so much of your time, I'm trying to undestand this. There are functions that I havent used before. It looks good, but for some reason I can't get it to do anything. I receive an error message saying no variable given for 'Dim', 'Global', 'Local' or 'Const' statement. Perhaps it has something to do with the older version of AutoIt that I am still using, or maybe I'm just doing something wrong? I don't see why it would work for you and not for me. :) Maybe I need a bit more time. I cant find the operator '&=' in my help file, so it probably won't work until I upgrade anyway. I will do this in a couple of days.

First I need to test drive my Automatic Ledger and clean it up a bit. The ledger seems to work quite well. There are a lot of different types of entry to make, so I'm quite pleased. It keeps track of debtors and creditors, it care of sales and purchases, updates payments in the cash or bank book and produces a trial balance, which always seems to balance. I think the only limitation is the human entering data. I estimate between 5 and 10 seconds for each transaction. At this speed it should be possible to do a whole years accounts in less than two hours. :P

Getting back to the question, I can explain this in a simpler way. Imagine a piano keyboard. Label all the black keys '1' and all the white keys '0'. All black keys are separated by at least one white note. The keyboard can be represented by the following binary string:

010100101010

Conduct a search for two adjacent black notes which are separated by one white (or black) note: 3 Results found.

010100101010

Suppose I now paint one of the white keys black. Will the search find any new results? The answer is: No.

011100101010

Suppose I now paint another white key black, adjacent to the first. Will the search find any new results? The answer is: Yes.

011110101010

The third and fifth terms of the string now fit the search criteria, as do terms five and seven: 5 Results found.

Edited by czardas

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