Jump to content

text left right trim


Recommended Posts

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

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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

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

Link to comment
Share on other sites

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

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

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

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