Jump to content

EASY String Spliter UDF


pingpong24
 Share

Recommended Posts

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

  • Moderators

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

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.

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

Link to comment
Share on other sites

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

  • Moderators

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

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.

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