Jump to content

StringFetch


Newb
 Share

Recommended Posts

I wrote this, much effort, then i discovered later that there someone already wrote _StringBetween, and killed the first 5 people that passed in front of me, while in prey of rage. At least it was a good exercise.

Enjoy. :x

EDIT: It came up that i needed this function because _StringBetween didn't worked in my script. WIN!

PS: This function has more arguments than _StringBetween, you can set also all the arguments of the StringInStr function. HA! I did better FU original Stringbetween writer :P (Just kiddin))

With the main function with carriages so it's more readable:

Func StringFetch($c_String,$c_StringSearchA,$c_StringSearchB,$i_InstrCaseSense=0,$i_InstrOccurrence=1,$i_InstrStart=1,$i_InstrCount=50000)
    Local $c_StringASize=StringLen($c_StringSearchA)
    If $i_InstrStart=False Then $c_StringASize=1
    Local $c_Fetched=StringMid($c_String,StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount) _
    +$c_StringASize,StringInStr($c_String,$c_StringSearchB,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount) _
    -(StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount)+$c_StringASize))
    Return $c_Fetched
EndFunc

With the main function in One line (Exactly the same as above, just the main function was very long, and here it's all in one line):

Func StringFetch($c_String,$c_StringSearchA,$c_StringSearchB,$i_InstrCaseSense=0,$i_InstrOccurrence=1,$i_InstrStart=1,$i_InstrCount=50000)
    Local $c_StringASize=StringLen($c_StringSearchA)
    If $i_InstrStart=False Then $c_StringASize=1
    Local $c_Fetched=StringMid($c_String,StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount)+$c_StringASize,StringInStr($c_String,$c_StringSearchB,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount)-(StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount)+$c_StringASize))
    Return $c_Fetched
EndFunc

Example of use:

Global $String="Samuel Taylor Coleridge was a british writer who wrote The Rime of The Ancient Mariner Poetry"
Global $x=StringFetch($String,"ish "," who"); I want to extract the word "writer" in thi example
MsgBox(0,"PO",$x)
Func StringFetch($c_String,$c_StringSearchA,$c_StringSearchB,$i_InstrCaseSense=0,$i_InstrOccurrence=1,$i_InstrStart=1,$i_InstrCount=50000)
    Local $c_StringASize=StringLen($c_StringSearchA)
    If $i_InstrStart=False Then $c_StringASize=1
    Local $c_Fetched=StringMid($c_String,StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount) _
    +$c_StringASize,StringInStr($c_String,$c_StringSearchB,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount) _
    -(StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount)+$c_StringASize))
    Return $c_Fetched
EndFunc

All the arguments with $C_Instr prefix are the StringInStr arguments, check helpfile for info.

EDIT: I Implemented in my script _StringBetween with the RIGHT syntax, and it doesn't work, so it turned out that my funcion works and _StringBetween doesnt (In my script)

GUICtrlSetData($NameLabel,_StringBetween($TextToCheck,'Name:','['))

This function doesn't retrevie the text which is in middle at all while mine does. YAY! I didn't wrote it for nothing

Edited by Newb

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Link to comment
Share on other sites

  • 4 weeks later...

I wrote this, much effort, then i discovered later that there someone already wrote _StringBetween, and killed the first 5 people that passed in front of me, while in prey of rage. At least it was a good exercise.

Enjoy. :)

EDIT: It came up that i needed this function because _StringBetween didn't worked in my script. WIN!

PS: This function has more arguments than _StringBetween, you can set also all the arguments of the StringInStr function. HA! I did better FU original Stringbetween writer ;) (Just kiddin))

With the main function with carriages so it's more readable:

Func StringFetch($c_String,$c_StringSearchA,$c_StringSearchB,$i_InstrCaseSense=0,$i_InstrOccurrence=1,$i_InstrStart=1,$i_InstrCount=50000)
    Local $c_StringASize=StringLen($c_StringSearchA)
    If $i_InstrStart=False Then $c_StringASize=1
    Local $c_Fetched=StringMid($c_String,StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount) _
    +$c_StringASize,StringInStr($c_String,$c_StringSearchB,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount) _
    -(StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount)+$c_StringASize))
    Return $c_Fetched
EndFunc

With the main function in One line (Exactly the same as above, just the main function was very long, and here it's all in one line):

Func StringFetch($c_String,$c_StringSearchA,$c_StringSearchB,$i_InstrCaseSense=0,$i_InstrOccurrence=1,$i_InstrStart=1,$i_InstrCount=50000)
    Local $c_StringASize=StringLen($c_StringSearchA)
    If $i_InstrStart=False Then $c_StringASize=1
    Local $c_Fetched=StringMid($c_String,StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount)+$c_StringASize,StringInStr($c_String,$c_StringSearchB,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount)-(StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount)+$c_StringASize))
    Return $c_Fetched
EndFunc

Example of use:

Global $String="Samuel Taylor Coleridge was a british writer who wrote The Rime of The Ancient Mariner Poetry"
Global $x=StringFetch($String,"ish "," who"); I want to extract the word "writer" in thi example
MsgBox(0,"PO",$x)
Func StringFetch($c_String,$c_StringSearchA,$c_StringSearchB,$i_InstrCaseSense=0,$i_InstrOccurrence=1,$i_InstrStart=1,$i_InstrCount=50000)
    Local $c_StringASize=StringLen($c_StringSearchA)
    If $i_InstrStart=False Then $c_StringASize=1
    Local $c_Fetched=StringMid($c_String,StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount) _
    +$c_StringASize,StringInStr($c_String,$c_StringSearchB,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount) _
    -(StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount)+$c_StringASize))
    Return $c_Fetched
EndFunc

All the arguments with $C_Instr prefix are the StringInStr arguments, check helpfile for info.

EDIT: I Implemented in my script _StringBetween with the RIGHT syntax, and it doesn't work, so it turned out that my funcion works and _StringBetween doesnt (In my script)

GUICtrlSetData($NameLabel,_StringBetween($TextToCheck,'Name:','['))

This function doesn't retrevie the text which is in middle at all while mine does. YAY! I didn't wrote it for nothing

hi,does you use the array?
Link to comment
Share on other sites

  • 4 weeks later...

hi,does you use the array?

What do you mean with do you use the array?

Anyway, Improved version of the script:

Func StringFetch($c_String,$c_StringSearchA,$c_StringSearchB,$i_InstrCaseSense=0,$i_InstrOccurrence=1,$i_InstrStart=1,$i_InstrCount=50000)
    Local $c_StringASize=StringLen($c_StringSearchA)
    If $i_InstrStart=False Then $c_StringASize=1
    Return StringMid($c_String,StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount) _
    +$c_StringASize,StringInStr($c_String,$c_StringSearchB,$i_InstrCaseSense,$i_InstrOccurrence,StringInStr($c_String,$c_StringSearchA),$i_InstrCount) _
    -(StringInStr($c_String,$c_StringSearchA,$i_InstrCaseSense,$i_InstrOccurrence,$i_InstrStart,$i_InstrCount)+$c_StringASize))
EndFunc

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

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...