Jump to content

Missing a character while stepping through an Array


random42
 Share

Recommended Posts

This is REALLY odd.

There is probably a much more ellegant way to do this code and eventually I'll want to learn it, but for now I'm just stumped on this odd error and would like to know what causes it and how to avoid it in the future.

In a nutshell:

While pulling data off a web page a single character is acting differently than the other characters around it. It looks identical in the array (array output from cap to a file is below my function code) and in the page source code (below the array output).

This pulls info off a web page into an array via $sBlanks = _IEBodyReadText($oIE).

It then breaks the info into another array with an element for each line - function below.

If does this by starting at a designated location and stepping through one character at a time, entering the character into the destenation array element until it comes to a number, then it redims and starts the next line of the source array.

This all works fantastically great up until the very end when instead of seeing a character it is seeing a blank of some sort.

If you look I have a couple variables called weirdchar and weirdchar2. They returned blanks in my debug message box similar to what is happening here. One is a line break or something and the other is a space of some sort that isn't the standard ANSI space.

The issue happens with the 'f' in "soft" on 14 down. There are other 'f' characters that are unaffected however the 'f' in 'fade' in 12 across appears to have the same issue. I hadn't noticed until just now when I was verifying my data before hitting the post button.

In my code, I have some of my msgboxes and _arraydisplays that I was debugging with commented out currently but the odd thing is that if I display the array at any point in time the 'f' appears there. Strangely when displaying the character that is held by $char it goes blank on that 'f' even though the source that it is pulling the characters from displays it. (See the two lines prior to the last next are commented out at this point though I tried that before posting.)

Thanks if advance for anyone with any ideas. This is really odd.

The code is here:

func _ArrayParsebyNumber(const byref $aSourceArray, $sStartChar, $sStopChar, $aDestArray)
;MsgBox(0,"","1")
    _ArrayDisplay($aSourceArray,"")
    for $x = $sStartChar to $sStartChar
        $weirdchar=stringmid($aSourceArray[0],$x,1)
    Next
    for $x = $sStartChar+1 to $sStartChar+1
        $weirdchar2=stringmid($aSourceArray[0],$x,1)
    Next
;msgbox(0,"weird","")
;MsgBox(0,"test weird checl","x" & $weirdchar & "x")
    
    If IsArray($aSourceArray) Then
    Else
        MsgBox(0,"myERROR","Source Array not an Array")
    EndIf
    If IsArray($aDestArray) Then
    Else
        MsgBox(0,"myERROR","Dest Array not an Array")
    EndIf
    
    $y=0
    $numflag=0
    $ansflag=0
    for $x = $sStartChar to $sStopChar
        $char=stringmid($aSourceArray[0],$x,1)
        if $char=stringmid($aSourceArray[0],1,1) Then
            $char=" "
        EndIf
        
    ;MsgBox(0,"answer flag",$ansflag)
        If $char="1" Then
            If $ansflag=1 Then
                $y = $y+1
                ReDim $aDestArray[UBound($aDestArray) + 1]
                $ansflag=0
                $aDestArray[$y]=$aDestArray[$y] & $char
            Else
                $aDestArray[$y]=$aDestArray[$y] & $char
            EndIf           
        ElseIf $char=$weirdchar Then
        ;msgbox(0,"weird keying?","")
        ElseIf $char=$weirdchar2 Then
        ;msgbox(0,"weird2 keying?","")
        ElseIf $char=" " Then
        ;MsgBox(0,"space keying?","")
        ElseIf $char="." Then
        ElseIf $char="2" Then
            If $ansflag=1 Then
                $y = $y+1
                ReDim $aDestArray[UBound($aDestArray) + 1]
                $ansflag=0
                $aDestArray[$y]=$aDestArray[$y] & $char
            Else
                $aDestArray[$y]=$aDestArray[$y] & $char
            EndIf           
        ElseIf $char="3" Then
            If $ansflag=1 Then
                $y = $y+1
                ReDim $aDestArray[UBound($aDestArray) + 1]
                $ansflag=0
                $aDestArray[$y]=$aDestArray[$y] & $char
            Else
                $aDestArray[$y]=$aDestArray[$y] & $char
            EndIf           
        ElseIf $char="4" Then
            If $ansflag=1 Then
                $y = $y+1
                ReDim $aDestArray[UBound($aDestArray) + 1]
                $ansflag=0
                $aDestArray[$y]=$aDestArray[$y] & $char
            Else
                $aDestArray[$y]=$aDestArray[$y] & $char
            EndIf           
        ElseIf $char="5" Then
            If $ansflag=1 Then
                $y = $y+1
                ReDim $aDestArray[UBound($aDestArray) + 1]
                $ansflag=0
                $aDestArray[$y]=$aDestArray[$y] & $char
            Else
                $aDestArray[$y]=$aDestArray[$y] & $char
            EndIf           
        ElseIf $char="6" Then
            If $ansflag=1 Then
                $y = $y+1
                ReDim $aDestArray[UBound($aDestArray) + 1]
                $ansflag=0
                $aDestArray[$y]=$aDestArray[$y] & $char
            Else
                $aDestArray[$y]=$aDestArray[$y] & $char
            EndIf           
        ElseIf $char="7" Then
            If $ansflag=1 Then
                $y = $y+1
                ReDim $aDestArray[UBound($aDestArray) + 1]
                $ansflag=0
                $aDestArray[$y]=$aDestArray[$y] & $char
            Else
                $aDestArray[$y]=$aDestArray[$y] & $char
            EndIf           
        ElseIf $char="8" Then
            If $ansflag=1 Then
                $y = $y+1
                ReDim $aDestArray[UBound($aDestArray) + 1]
                $ansflag=0
                $aDestArray[$y]=$aDestArray[$y] & $char
            Else
                $aDestArray[$y]=$aDestArray[$y] & $char
            EndIf           
        ElseIf $char="9" Then
            If $ansflag=1 Then
                $y = $y+1
                ReDim $aDestArray[UBound($aDestArray) + 1]
                $ansflag=0
                $aDestArray[$y]=$aDestArray[$y] & $char
            Else
                $aDestArray[$y]=$aDestArray[$y] & $char
            EndIf           
        ElseIf $char="0" Then
            If $ansflag=1 Then
                $y = $y+1
                ReDim $aDestArray[UBound($aDestArray) + 1]
                $ansflag=0
                $aDestArray[$y]=$aDestArray[$y] & $char
            Else
                $aDestArray[$y]=$aDestArray[$y] & $char
            EndIf           
        Else
                $aDestArray[$y]=$aDestArray[$y] & $char
            $ansflag=1
        EndIf
;MsgBox(0,"current char",$char)
               ;_ArrayDisplay($aSourceArray,"source")
    Next
_ArrayDisplay($aDestArray,"dest")
_ArrayDisplay($aSourceArray,"source")
_ArrayDisplay($aArray,"orig")
    Return($aDestArray)
endfunc;->_ArrayParsebyNumber

The array data is here:

February 13

Across:
3. soul
5. jubjub
7. growl
10. city
12. fade
13. fish
15. osiri

Down:
1. kass
2. bunwich
4. huggy
6. ummagine
8. one
9. dive
11. tag
14. soft

Thank you

Source from page from affected area:

<div style="clear:both;"></div><strong>Tuesday, February 13<br /><br />Across:</strong><br />3. soul<br />5. jubjub<br />7. growl<br />10. city<br />12. fade<br />13. fish<br />15. osiri<br /><br /><strong>Down:</strong><br />1. kass<br />2. bunwich<br />4. huggy<br />6. ummagine<br />8. one<br />9. dive<br />11. tag<br />14. soft<br /><br />Thank you to Lin for posting the answers! :)<div style="clear:both; padding-bottom:0.25em"></div><br><br>
Link to comment
Share on other sites

  • Moderators

It's hard to understand with it jumping from here to there, but StringRegExp() may be your friend here:

#include <array.au3>
$sString = '<div style="clear:both;"></div><strong>Tuesday, February 13<br /><br />Across:</strong><br />3. soul<br />5. jubjub<br />7. growl<br />10. city<br />12. fade<br />13. fish<br />15. osiri<br /><br /><strong>Down:</strong><br />1. kass<br />2. bunwich<br />4. huggy<br />6. ummagine<br />8. one<br />9. dive<br />11. tag<br />14. soft<br /><br />Thank you to Lin for posting the answers! :)<div style="clear:both; padding-bottom:0.25em"></div><br><br>'
$aAcross = _Across($sString)
_ArrayDisplay($aAcross, 'Across')
$aDown = _Down($sString)
_ArrayDisplay($aDown, 'Down')

Func _Across($sString)
    Local $aAcrossMain = StringRegExp($sString, '(?s)(?i)Across:(.*?)Down:', 1)
    If IsArray($aAcrossMain) = 0 Then Return SetError(1, 0, '')
    Local $aAllAcross = StringRegExp($aAcrossMain[0], '(?s)(?i)\>(\d*\.\s*.*?)\<', 3)
    If IsArray($aAllAcross) = 0 Then Return SetError(2, 0, '')
    Return $aAllAcross
EndFunc
Func _Down($sString)
    Local $aDownMain = StringRegExp($sString, '(?s)(?i)Down:(.*?)\s*\/\>\<br\s*\/\>', 1)
    If IsArray($aDownMain) = 0 Then Return SetError(1, 0, '')
    Local $aAllDown = StringRegExp($aDownMain[0], '(?s)(?i)\>(\d*\.\s*.*?)\<', 3)
    If IsArray($aAllDown) = 0 Then Return SetError(2, 0, '')
    Return $aAllDown
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...