Sign in to follow this  
Followers 0
pingpong24

EASY String Spliter UDF

9 posts in this topic

#1 ·  Posted (edited)

Hi,

I wrote this UDF because the standard funcations in autoit for doing this task is an hasle and also if someone elase ever wants to accomplish what i have done, they can search the forum and find this instead of wasting time like me.

:P

Func _GetStringMethod($String, $Starting, $Ending)
$Result = StringRegExp($String,'('&$Starting&')([^'&$Ending&']*)',1)
If @error = 0 And @extended Then Return $Result[1] 
EndFunc

(not my code, its Smoke N code)

Edited by pingpong24

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

He didn't like my example of the StringInStr(): http://www.autoitscript.com/forum/index.ph...ndpost&p=136062

This would be another example to return the same result and probably throw less errors:

Dim $String = 'gjsagjkajkgjalsgjls624623ajgkjlgkagajgas359283'
Dim $Starting = 'jka'
Dim $Ending = '62'

MsgBox(0, "Test", _GetStringBetween($String, $Starting, $Ending))

Func _GetStringBetween($String, $Starting, $Ending)
    If StringInStr($String, $Starting) And StringInStr($String, $Ending) Then
        $StL = StringTrimLeft($String, StringInStr($String, $Starting) - 1)
        $SeL = StringLeft($StL, StringInStr($StL, $Ending) + 1)
        $StringBetween = StringTrimLeft(StringTrimRight($SeL, StringLen($Ending)), StringLen($Starting))
        Return $StringBetween
    Else
        Return 0
    EndIf
EndFunc
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

or something like

Func _StringBetween($s_String, $s_Start, $s_End = 0)
    $s_Start = StringInStr($s_String, $s_Start)+StringLen($s_Start)
    return StringMid($s_String, $s_Start, StringInStr($s_String, $s_End)-$s_Start)
EndFunc

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Share this post


Link to post
Share on other sites

Nice one w0uter!!


[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

#6 ·  Posted (edited)

This might be useful:

Func _StringParse( $sString, $sStart, $sEnd, $iOccurance = 0 )
    Local $aA = StringSplit($sString, $sStart, 1), $aB = StringSplit($aA[_Test($iOccurance, _Test($iOccurance > 0, $iOccurance + 1, $aA[0] + $iOccurance + 1), $aA[0])], $sEnd, 1)
    Return $aB[1]
EndFunc

Func _Test( $bBool, $vTrue, $vFalse )
    If $bBool Then Return $vTrue
    Return $vFalse
EndFunc

MsgBox(0, "expect c", _StringParse("[a][b][c][d][e][f]", "[", "]", -4))

;positive occurance means search from left
;zero occurance means last occurance
;negative occurance means search from right

EDIT: Updated with negative occurance.

Edited by erifash

Share this post


Link to post
Share on other sites

Ha!... Funny how people come to the same conclusion in different ways... Nice one erifash!


[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

stringinstr would be better since the user now has to avoid using regexp operators like (\.{2,}

Why not use this function I wrote:
Func _RegFormat( $str )
    Local $a = StringSplit('\[]^:()?-.|{},*+', '')
    For $i = 1 to $a[0]
        $str = StringReplace($str, $a[$i], '\' & $a[$i])
    Next
    Return $str
EndFunc

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