RCLens Posted February 15, 2018 Share Posted February 15, 2018 I want to delete all previous characters after replacing my string. For instance: $text = "AABBCCDD" $result = StringReplace($text,"BBC, "") I will get : AACDD But I want only CDD, not AA. It means to remove all previous characters after using StringReplace function, can I have an ida to do it? Thank you. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 15, 2018 Moderators Share Posted February 15, 2018 RCLens, You need a RegEx to do that: $text = "AABBCCDD" $result = StringRegExpReplace($text, ".*BBC", "") ConsoleWrite($result & @CRLF) .* - All characters from the start until we find... BBC - ...this string "" - And replace it all with an empty string M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
SlackerAl Posted February 15, 2018 Share Posted February 15, 2018 I'm sure the regex is more efficient, but just to put another option out there.... $text = "AABBCCDD" $mark = "BBC" $length = StringLen($mark) + StringInStr($text, $mark) - 1 $result = StringTrimLeft($text, $length) MsgBox(0, "debug", $result) Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. Link to comment Share on other sites More sharing options...
RCLens Posted February 15, 2018 Author Share Posted February 15, 2018 1 hour ago, Melba23 said: RCLens, You need a RegEx to do that: $text = "AABBCCDD" $result = StringRegExpReplace($text, ".*BBC", "") ConsoleWrite($result & @CRLF) .* - All characters from the start until we find... BBC - ...this string "" - And replace it all with an empty string M23 The problem is, variable to replace by an empty characters is not always 'BBC'. The goal is to get what is added after a process in log file. It means : 1. Take 500 last characters from previous log file 2. Launch process where additionnal characters are gonna be added to this log file 3. Take last 800 characters from newest log file updated 4. With function StringReplace, replace from newest log file (step 3), 500 characters from step 1 by empty character (because last 500 characters from step 1 are in newest log file updated) 5. Remove previous characters after using Replace function to get what is added from step 3, only. 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