Sign in to follow this  
Followers 0
Clever1mba

text left right trim

19 posts in this topic

Hello

here is code for search websites in txt file

but have lot possibilty to improve

problem in this code it search http://

but if text file contain website link like this http://domain1.com http://domain2.com

it should be spreated to other line like this

http://domain1.com

http://domain2.com

if some one have littile time and trick plz improve that code for all

cheerzzzzzzzz

#include <Array.au3>

#include <GUIConstants.au3>

GUICreate("TEST SEARCH") 

$myedit=GUICtrlCreateEdit (""& @CRLF, 1,50,400,300,$ES_AUTOVSCROLL+$WS_VSCROLL)

GUISetState ()

Dim $DLine

$Text = "test.txt"

;^^^^^ YOU NEED TO SET THIS LOCATION ABOVE ^^^^

$NFile = FileOpen($Text, 0)

; Check if file opened for reading OK

If $NFile = -1 Then

    MsgBox(0, "Error", "Unable to open file.")

EndIf

Dim $Data_[101], $newID=""; to set-up for an array - if you want an array

; Read in lines of text until the EOF is reached

While 1

    $NLine = FileReadLine($NFile)

    If @error = -1 Then ExitLoop

        If $NLine <> "" Then

        ; for a string

  $string = "http://"

            if StringInStr( $NLine, $string,0 ,-1) Then

            $DLine = $NLine

  GUICtrlSetData( $myedit, $DLine & @CRLF,1)

  EndIf

     

    EndIf

WEnd

FileClose($NFile)

While 1

    $msg = GUIGetMsg()

   

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Wend

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

hello thanks

but still results r not good i get some extra text with result

xxxxxxhttp://domain.comxxxxxxx

how to trim that extra text to get clean resutls

#include <Array.au3>

#include <GUIConstants.au3>

GUICreate("TEST SEARCH") 

$myedit=GUICtrlCreateEdit (""& @CRLF, 1,50,400,300,$ES_AUTOVSCROLL+$WS_VSCROLL)

GUISetState ()

Dim $DLine

$Text = "index.htm"

;^^^^^ YOU NEED TO SET THIS LOCATION ABOVE ^^^^

$NFile = FileOpen($Text, 0)

; Check if file opened for reading OK

If $NFile = -1 Then

    MsgBox(0, "Error", "Unable to open file.")

EndIf

Dim $Data_[101], $newID=""; to set-up for an array - if you want an array

; Read in lines of text until the EOF is reached

While 1

    $NLine = FileReadLine($NFile)

    If @error = -1 Then ExitLoop

        If $NLine <> "" Then

        ; for a string

            if StringInStr( $NLine, "http://",0 ,-1) Then

            $DLine = StringReplace($NLine, " ", @CRLF)

  GUICtrlSetData( $myedit, $DLine & @CRLF,1)

  EndIf

     

    EndIf

WEnd

FileClose($NFile)

While 1

    $msg = GUIGetMsg()

   

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Wend

Edited by asimzameer

Share this post


Link to post
Share on other sites

look in help for string trim right and string trim left

( you still have not removed some of my comments in your script)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

hello

i try to put some filter and it give result much better now but lots of extrat text with result

i just want result like this

www.domain1.com

www.domain2.com

www.domain3.com

www.domain4.com

www.domain5.com

www.domain6.com

www.domain7.com

www.domain8.com

www.domain9.com

www.domain10.com

any one like to help build this proper

#include <Array.au3>

#include <GUIConstants.au3>

GUICreate("TEST SEARCH")

$myedit=GUICtrlCreateEdit (""& @CRLF, 1,50,400,300,$ES_AUTOVSCROLL+$WS_VSCROLL)

GUISetState ()

Dim $DLine

$Text = "myfile.htm"

$NFile = FileOpen($Text, 0)

If $NFile = -1 Then

MsgBox(0, "Error", "Unable to open file.")

EndIf

Dim $Data_[101], $newID=""

While 1

$NLine = FileReadLine($NFile)

If @error = -1 Then ExitLoop

If $NLine <> "" Then

if StringInStr( $NLine , 'www' ) Then

$DLine1 = StringReplace($NLine, " ", @CRLF)

$DLine2 = StringReplace($DLine1, ">", @CRLF)

$DLine3 = StringReplace($DLine2, "<", @CRLF)

$DLine4 = StringReplace($DLine3, "http", @CRLF)

$DLine5 = StringReplace($DLine4, "," , @CRLF)

$DLine6 = StringReplace($DLine5, "/" , @CRLF)

$DLine7 = StringReplace($DLine6, "\" , @CRLF)

$DLine8 = StringReplace($DLine7, ";" , @CRLF)

$DLine9 = StringReplace($DLine8, ":" , @CRLF)

$DLine10 = StringReplace($DLine9, "[" , @CRLF)

$DLine11 = StringReplace($DLine10, "]" , @CRLF)

$DLine12 = StringReplace($DLine11, "}" , @CRLF)

$DLine13 = StringReplace($DLine12, "{" , @CRLF)

$DLine14 = StringReplace($DLine13, "%" , @CRLF)

$DLine15 = StringReplace($DLine14, "+" , @CRLF)

$DLine16 = StringReplace($DLine15, "=" , @CRLF)

$DLine17 = StringReplace($DLine16, ")" , @CRLF)

$DLine18 = StringReplace($DLine17, "(" , @CRLF)

$DLine19 = StringReplace($DLine18, "-" , @CRLF)

$DLine20 = StringReplace($DLine19, "'" , @CRLF)

$DLine21 = StringReplace($DLine20, '"' , @CRLF)

GUICtrlSetData( $myedit, $DLine21 & @CRLF,1)

EndIf

EndIf

WEnd

FileClose($NFile)

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Wend

Share this post


Link to post
Share on other sites

I havent the time to really get into this project with you, but just looking over the above code I notice you are replacing alot of special characters with @CRLF which creates a newline, so you are going to have alot of white space.

If you are wanting a clean list you may need to use the RegExp() in the beta version, and or learn the StringTrim() functions.

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

First

When you want to show your script use this

[ code ]

************** copy paste your code here

[ / code]

without spaces, looks like this

********* copy/paste your code here

then we can see if it is correct

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

hello Valuater

okay chk now

and tell how to use StringRegExp in code

StringRegExp ( "test", "pattern", [ flag ])

#include <Array.au3>
#include <GUIConstants.au3>
GUICreate("TEST SEARCH") 
$myedit=GUICtrlCreateEdit (""& @CRLF, 1,50,400,300,$ES_AUTOVSCROLL+$WS_VSCROLL)
GUISetState ()
Dim $DLine

$Text = "myfile.htm"

$NFile = FileOpen($Text, 0)

If $NFile = -1 Then
MsgBox(0, "Error", "Unable to open file.")
EndIf

Dim $Data_[101], $newID=""
While 1
$NLine = FileReadLine($NFile)
If @error = -1 Then ExitLoop
If $NLine <> "" Then

if StringInStr( $NLine , 'www' ) Then
$DLine1 = StringReplace($NLine, " ", @CRLF)
$DLine2 = StringReplace($DLine1, ">", @CRLF)
$DLine3 = StringReplace($DLine2, "<", @CRLF)
$DLine4 = StringReplace($DLine3, "http", @CRLF)
$DLine5 = StringReplace($DLine4, "," , @CRLF)
$DLine6 = StringReplace($DLine5, "/" , @CRLF)
$DLine7 = StringReplace($DLine6, "\" , @CRLF)
$DLine8 = StringReplace($DLine7, ";" , @CRLF)
$DLine9 = StringReplace($DLine8, ":" , @CRLF)
$DLine10 = StringReplace($DLine9, "[" , @CRLF)
$DLine11 = StringReplace($DLine10, "]" , @CRLF)
$DLine12 = StringReplace($DLine11, "}" , @CRLF)
$DLine13 = StringReplace($DLine12, "{" , @CRLF)
$DLine14 = StringReplace($DLine13, "%" , @CRLF)
$DLine15 = StringReplace($DLine14, "+" , @CRLF)
$DLine16 = StringReplace($DLine15, "=" , @CRLF)
$DLine17 = StringReplace($DLine16, ")" , @CRLF)
$DLine18 = StringReplace($DLine17, "(" , @CRLF)
$DLine19 = StringReplace($DLine18, "-" , @CRLF)
$DLine20 = StringReplace($DLine19, "'" , @CRLF)
$DLine21 = StringReplace($DLine20, '"' , @CRLF)

GUICtrlSetData( $myedit, $DLine21 & @CRLF,1)
EndIf

EndIf
WEnd
FileClose($NFile)
While 1
$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
Edited by asimzameer

Share this post


Link to post
Share on other sites

I understand this is your results you want to clean-up

xxxxxxhttp://domain.comxxxxxxx

$test = "xxxxxxhttp://domain.comxxxxxxx"

$result = StringTrimLeft( $test, 6)

will give this

$result = "http://domain.comxxxxxxx"

then

$result_2 = StringTrimRight( $result, 7)

final line

$result_2 = "http://domain.com"

and thats the approach

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

opps

man its not necessary it just example xxxxxxhttp://domainxxxxx

myfile.html contain links but we donno how much text contain at left and right

i have simple question that how can result be neat if html contain url

link

we donno myfile.htm contain how many links we just want to extract

with clean results

just simply do path one html file contain few webiste links and chk ur self with code

and notice result are not clean and clear

i hope u get my point

Edited by asimzameer

Share this post


Link to post
Share on other sites

If it's an html file you're searching through, then just get all the anchor text.

Like this:

<a href="http://www.autoitscript.com">AutoIt</a>

so, search for '<a href=' and then read until an endquote (or double quote) or a greater-than symbol.

Share this post


Link to post
Share on other sites

i got it with string trim also

$test = "xxwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxhttp://my-domain.comxxxxxssssssssssssssssssssssxx"

$L_loc = StringInStr($test, "http")

$result = StringTrimLeft( $test, $L_loc -1)

$R_loc = StringInStr($result, ".com", 0, -1)

$result_2 = StringLeft( $result, $R_loc +3)

MsgBox(0,"test", "final result = " & $result_2)

good luck

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

okay valuater i add this code and results much better now but lots of duplicate copies

one more thing i want to search now multiple file like *.htm *.php *.asp

im mean if folder contain lots off html asp and php file can we search all of them and get results

if yes plz tell me wat exact code would be

THANKS

Edited by asimzameer

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

results much better now but lots of duplicate copies

#include <GUIConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <String.au3>

Dim $result_3 = ""

$test = "xxwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxhttp://my-domain.comxxxxxssssssssssssssssssssssxx"

$L_loc = StringInStr($test, "http")

$result = StringTrimLeft( $test, $L_loc -1)

$R_loc = StringInStr($result, ".com", 0, -1)

$result_2 = StringLeft( $result, $R_loc +3)

If $result_2 <> $result_3 Then
    $result_3 = $result_2
;write the line to the file
    MsgBox(0,"test", "final result = " & $result_3)
EndIf

this will stop duplicates

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

one more thing i want to search now multiple file like *.htm *.php *.asp

im mean if folder contain lots off html asp and php file can we search all of them and get results

You want to do a loop inside of a loop... you should follow this post too

http://www.autoitscript.com/forum/index.php?showtopic=13255#

good luck

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

i did'nt get somthing at url have any example of multiple file search then plz share it

Share this post


Link to post
Share on other sites

one more thing i want to search now multiple file like *.htm *.php *.asp

im mean if folder contain lots off html asp and php file can we search all of them and get results

Step 1

You need to place your current search below this or in a function.... i will use a function call for this example.... its hard to explain everything

Func HTML_Search()

******all of your previous search patern goes in here*** so we can *call* it after searching for the above requested files*******

EndFunc

Step 2

Use this *you need to alter for your computer* to search for the above files

$Loc =  @HomeDrive & "\*.html"

RunWait(@ComSpec & ' /c ' & 'dir "' & $Loc & '" /a :h /b /s' & ' > "' & @TempDir & '\dir.txt"', '', @SW_HIDE)
    Sleep(2000)
    
    
    $LFile = FileOpen(@TempDir & "\dir.txt", 0)
    
; Check if file opened for reading OK
    If $LFile = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Return
    EndIf
    
; Read in lines of text until the EOF is reached
    While 1
        $LLine = FileReadLine($LFile)
        If @error = -1 Then ExitLoop
        If $LLine <> "" Then
            Call("HTML_Search"); this sends the info to the original file search
            $Msg2 = GUIGetMsg()
            If $Msg2 = $GUI_EVENT_CLOSE Then    ExitLoop
        EndIf
    WEnd
    FileClose($hFile)

hope you understand the idea

you have to search for the files you want (with this new search).... then

search inside those files with your other/original search

good luck

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

i trying this but its just scrolling with no result

#include <Array.au3>
#include <GUIConstants.au3>
GUICreate("TEST SEARCH")  
$myedit=GUICtrlCreateEdit (""& @CRLF, 1,50,400,300,$ES_AUTOVSCROLL+$WS_VSCROLL)
GUISetState ()
Dim $DLine


$Loc =  @HomeDrive & "\*.html"

RunWait(@ComSpec & ' /c ' & 'dir "' & $Loc & '" /a :h /b /s' & ' > "' & @TempDir & '\dir.txt"', '', @SW_HIDE)
    Sleep(2000)
    
    
    $NFile = FileOpen(@TempDir & "\dir.txt", 0)
    




If $NFile = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
EndIf

Dim $Data_[101], $newID=""
While 1
    $NLine = FileReadLine($NFile)
    If @error = -1 Then ExitLoop
        If $NLine <> "" Then








    EndIf
WEnd
FileClose($NFile)
While 1
    Call("HTML_Search")
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Wend
    
    
    
        
Func HTML_Search()
$L_loc = StringInStr($NLine, "http")
$result = StringTrimLeft( $NLine, $L_loc -1)
$R_loc = StringInStr($result, ".com", 0, -1)
$result_2 = StringLeft( $result, $R_loc +3)
GUICtrlSetData( $myedit,   $result_2 & @CRLF,1)
EndFunc

Share this post


Link to post
Share on other sites

you have completely "mixed" the two searches

they are "two" seperate searches

The one i just gave you will find the *.html files

the one you already had with read the *.html files

ok

8)


NEWHeader1.png

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