Sign in to follow this  
Followers 0
eadthem

Problems With Stringinstr

10 posts in this topic

ok first the program is supost to move to the top of a open wordpad document(works)

select a line of text (works)

make it all lower case (works)

strip spaces tabs enters (works)

then incrment tabcount everytime a starting html tag is found (finds some)

and de incrment evertime a ending html tag is found(finds some)

last tab over once for one in tabcount

it seams it find most tags that are at the begennign of a line

but it cannot find a tag if its at the end

example green found red couldtn find

<td>Tier5</td>

im using SciTE Version 1.68 i usest to use notepad for autoit but it makes it easer

and autoit v3.1.1

i chekced the beta and bug pages also looked at patch notes and i didnt see anything listed for thsi command of this nature

file sample im having it parse

<!--#include virtual="/headlm.ssi.htm" -->
<p><strong><font color="#ff0000"></font></strong></p>

<table>
<tr height="25">
<td colspan="1" rowspan="3" width="100">
<br>Tier5</td>
<td rowspan="1" colspan="8" id="skh" align="center" width="416">  Rebel Alliance Master Pilot<br>7500000 XP  box 18</td></tr><tr><td width="416">xp<br>single player</td><td width="76">skill sheet box<br>multi player</td><td width="167">xp<br></td><td width="100">skill
sheet box<br>

the program

global $tabcountf
global $tabcount
global $main
global $title
global $titleb
$titleb = "Notepad"
$title = "WordPad"
Opt("WinTitleMatchMode", 2)
Opt("SendKeyDelay", 0)       ;5 milliseconds
Opt("WinTextMatchMode", 0)
WinActivate ( $title )
WinWaitActive( $title )
$tabcountf = 0
$tabcount = 0
    For $pgup = 10 to 0 Step -1
        Send ( "{PGUP}", 0 )
    next
while WinActive( $title )
    WinWaitActive( $title )
    Send ( "{END}", 0 ) 
    Send ( "{HOME}", 0 )
    Send ( "{SHIFTDOWN}", 0 )
    Send ( "{END}", 0 )
    Send ( "{SHIFTUP}", 0 )
    Send ( "^c", 0 )
    Send ( "{RIGHT}", 0 )
    $main = ClipGet()
    $main = StringStripWS( $main , 8 )
    $main = StringLower( $main )
;$main = StringReplace ( $main, "<" , " <")
    if not 0 == StringInStr( $main, "<table", 0 , 1 ) Then
        $tabcount = $tabcount + 1
    endif 
    if not 0 == StringInStr( $main, "<tr", 0 , 1 ) then
        $tabcount = $tabcount + 1
    endif 
    if not 0 == StringInStr( $main, "<td", 0 , 1 ) then
        $tabcount = $tabcount + 1
    endif 
    if not 0 == StringInStr( $main, "<font", 0 , 1 ) then
        $tabcount = $tabcount + 1
    endif 
    if not 0 == StringInStr( $main, "</table>", 0 , 1 ) then
        $tabcount = $tabcount - 1
    endif 
    if not 0 == StringInStr( $main, "</tr>", 0, 1 ) then
        $tabcount = $tabcount - 1
    endif 
    if not 0 == StringInStr( $main, "</td>", 0 , 1 ) then
        $tabcount = $tabcount - 1
    endif 
    if not 0 == StringInStr( $main, "</font>", 0 , 1 ) then
        $tabcount = $tabcount - 1
    EndIf
    
;If  0 > $tabcount then
;   $tabcount = 0
;EndIf
    ConsoleWrite( $main & "tc" & @lf)
    ConsoleWrite( $tabcount & "tf" & @lf)
    $tabcountf = $tabcount
    While $tabcountf > 0
        $tabcountf = $tabcountf - 1
        
        Send ( "{TAB}", 0 )
    wend
    
wend

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I tested this on your example, since there is no </table> in your example it returned 1:

You will need Beta to run it:

Local $h_DOWNLOADFILE = @DesktopDir & '\TXT_Files\testing.txt'
Local $tabcount = 0, $StartTags[5] = ['', '<table>', '<tr', '<td', '<font'], $EndTags[5] = ['', '</table>', '</tr>', '</td>', '</font>']

For $i_Count = 1 To UBound($StartTags) - 1
    $Test = _GetTagInfo($h_DOWNLOADFILE, $StartTags[$i_Count], $EndTags[$i_Count])
    If Not IsArray($Test) Then $tabcount = $tabcount + 1
Next

MsgBox(0, '', $tabcount)

Func _GetTagInfo($s_FilePath, $s_Start, $s_End)
    $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3)
    If @error == 0 Then Return $a_Array
EndFunc
Edit:

Forgot to add in the MsgBox() So you can see

Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

;$main = StringReplace ( $main, "<" , " <")
    if not 0 == StringInStr( $main, "<table", 0 , 1 ) Then
        $tabcount = $tabcount + 1
    endif
The part of your script above show you of this

Not 0

Not 0 is 1, so why not use 1? (*operator precedence)

StringInStr is a boolean type of function, so just using the below would do

if StringInStr( $main, "<table", 0 , 1 ) Then

and checking if not, then

if not StringInStr( $main, "<table", 0 , 1 ) Then

:think:

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The part of your script above show you of this

Not 0

Not 0 is 1, so why not use 1? (*operator precedence)

in binary thats true but from what i read in the help file the oprand StringInStr "helpfile on StringInStr"Success: Returns the position of the substring"" and only 0 if it finds nothing so

if not 0 means if it found anything for the quarry then incrment

the way i read it it outputs more than just true or false least thats why i wrote it that way if it can be made to put out a bool i would like to know how as it would symplfie things.

SmOke_N i will half to download beta and try it tomarow as 2 of the operans you used arnt even in my version

you did give me a idea i could make it work off of files and it would work lot faster

thanks

Edited by eadthem

Share this post


Link to post
Share on other sites

in binary thats true but from what i read in the help file the oprand StringInStr "helpfile on StringInStr"Success: Returns the position of the substring"" and only 0 if it finds nothing so

if not 0 means if it found anything for the quarry then incrment

the way i read it it outputs more than just true or false

SmOke_N i will half to download beta and try it tomarow as 2 of the operans you used arnt even in my version

you did give me a idea i could make it work off of files and it would work lot faster

thanks

I use that method in my RSS_FEED functions, it's the quickest way to parse through them that I found.. neogia made a great example of how to use the StringRegExp... Although my example will work for you, if you wish to do string manipulation in the future I suggest you take a look at it for some great advice... gl :think:.

[center]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.[/center]

Share this post


Link to post
Share on other sites

ok i found neogia's post

is it saying that it will work like stringInStr only it could tell if

</table  <!-- is in somthign like this -->

<br>fijwonaodjoj</table>dkjfljklsdf<br>

?

Share this post


Link to post
Share on other sites

ok i found neogia's post

is it saying that it will work like stringInStr only it could tell if

</table  <!-- is in somthign like this -->

<br>fijwonaodjoj</table>dkjfljklsdf<br>

?

I don't think I understand your question... The script I posted will work... And it's shorter/faster (have it in a loop and just put the factors you were looking for in an array). The way I have it set up, it will look between those code tags, so If it's an array you could actually just do a for/next loop on $Text (ubound($test) - 1) and get the information between each tag... But I noticed you were just looking to see if it was a true statement, so I have it setup like I do.

[center]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.[/center]

Share this post


Link to post
Share on other sites

in binary thats true but from what i read in the help file the oprand StringInStr "helpfile on StringInStr"Success: Returns the position of the substring"" and only 0 if it finds nothing so

if not 0 means if it found anything for the quarry then incrment

the way i read it it outputs more than just true or false least thats why i wrote it that way if it can be made to put out a bool i would like to know how as it would symplfie things.

StringInStr returns 0 on fail, but returns the position as an interger for success. A number that is Not 0 is boolean true. 0 is boolean false.

Example

If StringInStr('test', 't') Then MsgBox(0, 'Is t in test?', 'true')
If Not StringInStr('test', 't') Then MsgBox(0, 'Is t in test?', 'false')

If StringInStr('test', 'o') Then MsgBox(0, 'Is o in test?', 'true')
If Not StringInStr('test', 'o') Then MsgBox(0, 'Is o in test?', 'false')

Share this post


Link to post
Share on other sites

A number that is Not 0 is boolean true. 0 is boolean false.

ok i knew about 0 =false and 1=true didnt know that anythign other than 1 is also = to true

SmOke_N i was askign about the commands capabltys as Stringinstr did not alwase work as i needed

i was asking if it would beable to find stuff inside other text as Stringinstr was having problems finding tags at the end of a line

im gona get beta and work on it some more now that i got some sleep

Share this post


Link to post
Share on other sites

ok i knew about 0 =false and 1=true didnt know that anythign other than 1 is also = to true

SmOke_N i was askign about the commands capabltys as Stringinstr did not alwase work as i needed

i was asking if it would beable to find stuff inside other text as Stringinstr was having problems finding tags at the end of a line

im gona get beta and work on it some more now that i got some sleep

If I remember correctly, I had issues with code tags at one time using StringInStr() also... but the StringRegExp() seems to handle them quite nicely.

[center]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.[/center]

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