Sign in to follow this  
Followers 0
dogsurfer

Search string from starting position (parsing)

3 posts in this topic

Intuitively, I think there must be many people wanting to parse through text, so some solution must already exist. That is, find x, then from there find y (not just another occurrence of x). I have been writing custom code for each instance, but this is kind of what I would want. Is there a better way?

; Checks if a string contains a given substring, starting at a specified character position.
; Submitted by dogsurfer 2008-02-09.

; Syntax:  StringInStr2 ( "string", "substring" [, casesense [, occurrence [, start]]] )
; where start is the position from the left, regardless if occurrence is negative.

Func StringInStr2($string, $substring, $casesense = 0, $occurrence = 1, $start = 0)
    If $occurrence > 0 Then
        $string = StringTrimLeft($string, $start)
    Else
        $string = StringMid($string, 1, $start)
        $start = 0
    EndIf
    $position = StringInStr($string, $substring, $casesense, $occurrence)
    If $position > 0 Then Return $position + $start
EndFunc


$pos = 12; parsing example
$result = StringInStr2('I like Annette Funnicello', 'nn', 0, 1, $pos)
MsgBox(0, "StringInStr2 Forward Search Result", "The 'nn' in 'I like Annette Funnicello' starting from " & $pos & " is " & $result)

$result = StringInStr2('I like Annette Funnicello', 'nn', 0, -1, $pos)
MsgBox(0, "StringInStr2 Backward Search Result", "The 'nn' in 'I like Annette Funnicello' reversing from " & $pos & " is " & $result)

Share this post


Link to post
Share on other sites



I would just use StringInStr to find your "x", then trim left of that and StringInString for "y".

Although you could probably use a regex to simplify this process with a single line of code.


AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

I would just use StringInStr to find your "x", then trim left of that and StringInString for "y".

Although you could probably use a regex to simplify this process with a single line of code.

There it is: StringRegExp! It more exactly gets to what I'm trying to parse. Not overly intuitive though.

I consider it obscure when code can be written by using a spoon in bowl of alphabet cereal.

There is an old saying, You cant have your code, and eat it too. Approximately. Thanks for your help!

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