Queener Posted June 30, 2015 Posted June 30, 2015 I'm looking to delete string from point A to point B... For example:"I want to go to store"I would think I need 2 variables.$sfind1 = want$sfind2 = to.Anything between $sfind1 and $sfind2 will be delete it. I would think stringtrim left or right, but the problem I'm facing is, trim left/right does not have a point a or point b to trim from and to. It would be useful if a function was created to do this job if it doesn't already exist. Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
nitekram Posted June 30, 2015 Posted June 30, 2015 Try stringmid() 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator
Queener Posted June 30, 2015 Author Posted June 30, 2015 (edited) don't think that is correct... StringMid ( "string", start [, count = -1] )There's no point b... it can be used as StringMid("I want to go to store", 3, 3) this code would return 'wan' The issue here is; it's not always going to be I want to go to store all the time. It will randomize any letters and alphabet later in the future. Edited June 30, 2015 by asianqueen Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
nitekram Posted June 30, 2015 Posted June 30, 2015 (edited) Local $sString = "I want to go to store" Local $sDeleteString = StringMid($sString, StringInStr($sString, 'want'), StringInStr($sString, 'to')) MsgBox('','', StringReplace($sString, $sDeleteString, '')) If you want the second occurrence of the word 'to' it would be:Local $sString = "I want to go to store" Local $sDeleteString = StringMid($sString, StringInStr($sString, 'want'), StringInStr($sString, 'to', 0, 2)) MsgBox('','', StringReplace($sString, $sDeleteString, '')) Edited June 30, 2015 by nitekram 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator
mikell Posted June 30, 2015 Posted June 30, 2015 The issue here is; it's not always going to be I want to go to store all the time. It will randomize any letters and alphabet later in the future.Then a 'real' example is needed, because regular expressions can also do the job but they need precise requirementsLocal $sString = "I want to go to store" MsgBox('','', StringRegExpReplace($sString, 'I\h\K(.*?)\hto\h', "") ) MsgBox('','', StringRegExpReplace($sString, 'I\h\K(.*)\hto\h', "") )
Queener Posted June 30, 2015 Author Posted June 30, 2015 To make it easier identify, what about James's PC at //[start] St. Joseph with ID: 100275 Rm#c124 //[end] is not available. replace after //[start] to before //[end] with nothing. So it should be Jame's PC at //[start] //[end] is not available Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
iamtheky Posted June 30, 2015 Posted June 30, 2015 $sString = "James's PC at //[start] St. Joseph with ID: 100275 Rm#c124 //[end] is not available." $sRepl = stringregexpreplace($sString , "\/\/\[start\].*\/\/\[end\]" , "") msgbox(0, '' , $sRepl) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
iamtheky Posted June 30, 2015 Posted June 30, 2015 or this$sString = "James's PC at //[start] St. Joseph with ID: 100275 Rm#c124 //[end] is not available." msgbox(0, '' , _TrimFromAtoB($sString , "//[start]" , "//[end]")) Func _TrimFromAtoB($string , $a , $b) return stringleft($sString , stringinstr($sString , $a) - 1) & stringright($sString , stringlen($sString) - stringlen($b) - stringinstr($sString , $b)) EndFunc ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
mikell Posted June 30, 2015 Posted June 30, 2015 $sString = "James's PC at //[start] St. Joseph with ID: 100275 Rm#c124 //[end] is not available." $sRepl1 = stringregexpreplace($sString , "//\[start\]\h*\K.*(?=//\[end\])" , "") msgbox(0, "" , $sRepl1) $sRepl2 = stringregexpreplace($sString , "at\h*//\[start\].*//\[end\]" , "definitely") msgbox(0, "" , $sRepl2)Is this example appropriate or do you want a generic way ?
Queener Posted July 1, 2015 Author Posted July 1, 2015 (edited) sorry, I just got off from work on my 2nd job so I haven't tested. Will let you know how it goes after testing it. EDIT: Instead of using $sString; can I just have it look inside the file itself? i tried this with no success: $sFile = fileread($dummies) $sRepl1 = stringregexpreplace($sFile , "//\[offstart\]\h*\K.*(?=//\[offend\])" , "") ;filewrite($dummies, $sRep11) msgbox(0, "" , $sRepl1) what i mean by no success is; it didn't modify anything... It sees the texts, but didn't replace it with empty after [offstart] and before [offend] @boththose - your trim a to b works, but trimmed the whole [offstart] to [offend]. I actually want to leave those two for reference finding string next time I need to add more data. Edited July 1, 2015 by asianqueen Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
mikell Posted July 1, 2015 Posted July 1, 2015 Hmm last try$sRepl1 = stringregexpreplace($sFile , "(?s)(?<=//\[offstart\]).*?(?=//\[offend\])" , "") Queener 1
Queener Posted July 1, 2015 Author Posted July 1, 2015 Hmm last try$sRepl1 = stringregexpreplace($sFile , "(?s)(?<=//\[offstart\]).*?(?=//\[offend\])" , "") perfect! Thank you guys so much for helping. I was pretty frustrated on getting it to work the way I wanted. Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
mikell Posted July 1, 2015 Posted July 1, 2015 This still looks like a little wheel reinvention (because some people worked hard to provide nice includes) #include <String.au3> $sString = "James's PC at //[start] St. Joseph with ID: 100275 Rm#c124 //[end] is not available." $sRepl1 = StringReplace($sString , _StringBetween($sString ,"//[start]", "//[end]")[0] , " ") msgbox(0, "" , $sRepl1)
Queener Posted July 2, 2015 Author Posted July 2, 2015 i can apply this to xml also right? Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Queener Posted July 2, 2015 Author Posted July 2, 2015 (edited) hehehee... i used wrong... yes I can... though I'm not sure how to delete anything in between <!-- -->I tried $sRepl1 = stringregexpreplace($sFileRead , "(?s)(?=<!--).*?(?=-->)" , "" & @CRLF & @CRLF & "")It seems to elminate the <!-- and the data inside it, leaving out -->. Which I wanted to keep the <!-- and -->; just wipe out data in between those two. Edited July 2, 2015 by asianqueen Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
mikell Posted July 2, 2015 Posted July 2, 2015 There's a typo in your lookbehind(?=<!--) should be (?<=!--)
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