gamerman2360 Posted February 16, 2006 Share Posted February 16, 2006 MsgBox(0, "Test", StringStripBetween("I really like pizza!", " r", "y ")); returns "I like pizza!" Func StringStripBetween($string, $startstr, $endstr, $casesense = 0, $startocc = 1, $endocc = 1) If Not $startocc Or Not $endocc Then Return SetError(1) $start = StringInStr($string, $startstr, $casesense, $startocc) $end = StringInStr($string, $endstr, $casesense, $endocc) If Not $start Or Not $end Then Return SetError(2) $right = StringRight($string, StringLen($string) - $end) Return StringLeft($string, $start - 1) & $right EndFunc Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 16, 2006 Moderators Share Posted February 16, 2006 (edited) MsgBox(0, "Test", StringStripBetween("I really like pizza!", " r", "y ")); returns "I like pizza!" Func StringStripBetween($string, $startstr, $endstr, $casesense = 0, $startocc = 1, $endocc = 1) If Not $startocc Or Not $endocc Then Return SetError(1) $start = StringInStr($string, $startstr, $casesense, $startocc) $end = StringInStr($string, $endstr, $casesense, $endocc) If Not $start Or Not $end Then Return SetError(2) $right = StringRight($string, StringLen($string) - $end) Return StringLeft($string, $start - 1) & $right EndFuncI was looking at this and wondering what if there were more than 2 instances in one line what would happen, and as I thought, it only catches the first one. I did this one for you, I don't play with RegExp much at all, but it seemed to work... maybe you or someone else can make it better:MsgBox(0, "Test", EliminateBetween("I really like pizza, I really like extra cheese too!", " R", "y ")); returns "I like pizza, I like extra cheese too!" Func EliminateBetween($s_String, $s_Start, $e_End, $c_CaseSense = 0, $s_Space = '') If StringInStr($s_Start, ' ') Or StringInStr($e_End, ' ') Then $s_Space = ' ' If StringInStr($s_String, $s_Start) And StringInStr($s_String, $e_End) Then If $c_CaseSense = 0 Then $ReturnResult = StringRegExpReplace($s_String, '(?i:' & $s_Start & ')(?i:[^' & $e_End & ']*'& $e_End & ')', $s_Space) Else $ReturnResult = StringRegExpReplace($s_String, '(' & $s_Start & ')([^' & $e_End & ']*'& $e_End & ')', $s_Space) EndIf If @error = 0 And @extended Then Return StringStripWS($ReturnResult, 7) EndIf EndFunc Edit: I noticed yours had case sensitive, mine was originally hard coded to be case sensitive, but I think the above fixes that, and gives the option... someone might want to proof and or fix it if it doesn't (if they feel like it I should say ). Edited February 16, 2006 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 More sharing options...
zichd Posted February 16, 2006 Share Posted February 16, 2006 Thanks SmOke_N and gamerman2360 Usefull Regards Dan Link to comment Share on other sites More sharing options...
gamerman2360 Posted February 17, 2006 Author Share Posted February 17, 2006 Thanks SmOke_N and gamerman2360UsefullRegardsDanThanks, I don't get that often. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now