Jump to content

Find String By Tag UDF


AvaCompute
 Share

Recommended Posts

Easy solution to find string in html file.

FindStringByTag.au3

#include-once
;—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
;
;   Title ………………………… : Find string by tag.
;   Author(s) ……………… : AvaCompute
;   AutoIt Version … : 3.3.12.0
;
Func FindStringByTag( $String , $StartString , $EndString = '' , $CaseSense = 2 , $Occurrence  = 1 )
    Local $pStartString , $pEndString , $StartStringLength
    $StartStringLength = StringLen( $StartString )
    $pStartString = StringInStr( $String , $StartString , $CaseSense , $Occurrence )
    If ( $pStartString == 0 ) Then
        Return SetError( 1 , @error , '' )
    EndIf
    If ( $EndString ) Then
        $pEndString = StringInStr( $String , $EndString , $CaseSense , 1 , $pStartString + $StartStringLength )
        If ( $pEndString == 0 ) Then
            Return SetError( 2 , @error , '' )
        EndIf
        Return StringMid( $String , $pStartString + $StartStringLength , $pEndString - ( $pStartString + $StartStringLength ))
    Else
        Return StringLeft( $String , $pStartString - 1 )
    EndIf
EndFunc
;—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

Sample:

#include 'FindStringByTag.au3'
;—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
; 1 Tag
;
$String      = 'SSD 240 GB_A8ER37'
$StartString = '_'
$ProductName = FindStringByTag( $String , $StartString )
ConsoleWrite( '! [FindStringByTag] Product Name = ' & $ProductName & @CRLF )
;—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
; 2 Tag
;
$String      = '<meta property="fb:app_id" content="176044105761845" />'
$StartString = 'content="'
$EndString   = '"'
$ContentName = FindStringByTag( $String , $StartString , $EndString )
ConsoleWrite( '! [FindStringByTag] Content Name = ' & $ContentName & @CRLF )
;—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

Result:

! [FindStringByTag] Product Name = SSD 240 GB
! [FindStringByTag] Content Name = 176044105761845
Edited by AvaCompute
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...