Jump to content
Sign in to follow this  
evilertoaster

array problem.....

Recommended Posts

evilertoaster

hey, im trying to write a function that takes a long string of words and finds the most common x-length word in the string. so far ive made this (its got some debugging progress-bars on atm)-

$aline = "the quixk brown brown foxie fox did the jumpy over laaaazzzzyyyy dog the quick brown"
mcomw ($aline,4)

func mcomw ($string,$len)
    progresson ("state","starting")
    $size=stringlen ($string)/$len
    $size = round ($size) + 4
    dim $aray[$size][2]
    $start = 1
    while 1
        $sub=stringmid ($string,$start,$len)
        if @error = -1 then exitloop
        progressset ("state","current sub " & $sub)
        sleep (1000)
        $astart = 1
        $flag = "notfound"
        clipput ($astart)
        do                    
            if $sub = $aray[$astart][1] then
                $flag = "found"
                progressset (0,"state","found " & $sub)
                sleep (3000)
                exitloop
            endif
            sleep (100)
            progressset (0,"state", $astart & " of " & $size)
            $astart = $astart + 1
        until $astart + 2 = $size
        if $flag="found" then
            $aray[$astart][2] = $aray[$astart][2] + 1
            progressset (0,"state", "array count " & $aray[$astart][2])
            sleep (3000)
        endif
        if $flag = "notfound" then
            $astart = 1
            progressset (0,"state", "starting not found")
            sleep (3000)
            while 1
                if $aray[$astart][1] = "" then
                    $aray[$astart][1]= $sub
                    progressset (0,"state", "wrote " & $sub & " to array " & $aray[$astart][1])
                    sleep (3000)
                    exitloop
                endif
                $astart = $astart + 1
            wend
        endif
        $start = $start + 1
    wend
    clipput ($aray[1][1] & " " & $array[1][2])

endfunc

but it crashes becuase of some array error, also it says that some $sub is already presant when its not....if anyone has the time to accaulyl see what im doing and the kindess and briliance :) to help I'd sure appreciate it... thanks

edit: alternitivly if there is already someone who did this can you tell me where?

Edited by evilertoaster

Share this post


Link to post
Share on other sites
Lazycat

Without deep diving into code, problem with

dim $aray[$size][2]

second dimention is only 2 in size, but in code you adressing third element:

$aray[$astart][2] = $aray[$astart][2] + 1

As alternative, you can look into this:

$aline = "the quixk brown brown foxie fox did the jumpy over laaaazzzzyyyy dog the quick brown"

MsgBox (0, "title", MostCommonWord($aline, 5))

Func MostCommonWord($string, $len)
    Local $comWord = "", $comNum = 1, $num = 1
    $asWord = StringSplit($string, " ")
    For $i = 1 to $asWord[0]
        If StringLen($asWord[$i]) <> $len Then ContinueLoop
        For $j = $i+1 To $asWord[0]
            If $asWord[$i] <> $asWord[$j] Then ContinueLoop
            $num = $num + 1
        Next
        If $num > $comNum Then 
            $comNum = $num
            $comWord = $asWord[$i]
            $num = 1
        Endif
    Next
    Return($comWord)
Endfunc

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.