dersiniar Posted April 21, 2022 Share Posted April 21, 2022 Hi I have like 80 different strings that i need to map out and remove them as below. $test2 = StringReplace($test2, 'word',"") $test2 = StringReplace($test2, '/>',"") But can i make it some how different, instead making 80 new lines with same method? Is it possible somehing like this $Strings = ("word", "/>","more words") $test2 = StringReplace($test2, $Strings, "") Tested, didn't work lol Link to comment Share on other sites More sharing options...
Subz Posted April 21, 2022 Share Posted April 21, 2022 Try StringRegExpReplace you can test on your patterns here: RegExr: Learn, Build, & Test RegEx Link to comment Share on other sites More sharing options...
dersiniar Posted April 21, 2022 Author Share Posted April 21, 2022 (edited) 15 minutes ago, Subz said: Try StringRegExpReplace you can test on your patterns here: RegExr: Learn, Build, & Test RegEx Cant use that. i have about 80 sentences with all have words "nice sun", "Slow Motion", "Don't come today, in this place" in it. Some samplesspan class="a-size-nice sun-success"> br div cla s="a-row">span class="a-color-state">nice sun>div>div>spa . </span> nice sun <br Don't come today, in this place <brSo i use fallowing: Global $sResponse = StringInStr($sData, "nice sun") Global $test2 = StringMid($sData, $sResponse-50, "100") Global $sResponse = StringInStr($sData, "nice sun") Global $test2 = StringMid($sData, $sResponse-50, "50") $test2 = StringReplace($test2, 's="a-row">span class="a-color-state">',"") I need that 50 character $sResponse due different sentences and more results that i need from there. But i do not need all that other stuff Edited April 21, 2022 by dersiniar Link to comment Share on other sites More sharing options...
Subz Posted April 21, 2022 Share Posted April 21, 2022 Can you post the example text correctly, the example above is missing closing/opening tags is badly formatted. Link to comment Share on other sites More sharing options...
Musashi Posted April 21, 2022 Share Posted April 21, 2022 30 minutes ago, dersiniar said: But can i make it some how different, instead making 80 new lines with same method? Put the strings in an Array and loop through the array with a single StringReplace(). "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
dersiniar Posted April 21, 2022 Author Share Posted April 21, 2022 12 minutes ago, Subz said: Can you post the example text correctly, the example above is missing closing/opening tags is badly formatted. that's how they are, Those tags have to be missing cos its just a part randomly received from html. I just need to map out text what i need from it Link to comment Share on other sites More sharing options...
dersiniar Posted April 21, 2022 Author Share Posted April 21, 2022 (edited) 41 minutes ago, Musashi said: Put the strings in an Array and loop through the array with a single StringReplace(). I like the idea, But i do not know lol how to make it. $Strings = "1", "2", "3" For $i = 1 to Strings ;........;that part is always complicated for me how to make $String = $Strings, $i Next $test2 = StringReplace($test2, '$String',"") Edited April 21, 2022 by dersiniar Link to comment Share on other sites More sharing options...
Solution Musashi Posted April 21, 2022 Solution Share Posted April 21, 2022 2 hours ago, dersiniar said: I like the idea, But i do not know lol how to make it. Example : Local $aWords[4] = [3, "word", "/>", "more words"] Local $sString = "In the beginning was the word." & @CRLF & _ "After the word, there were more words, e.g. />" & @CRLF & _ "Now they are gone !" ConsoleWrite("Before : " & @CRLF & $sString & @CRLF & @CRLF) For $i = 1 To $aWords[0] $sString = StringReplace($sString, $aWords[$i], "") ; or use : ; $sString = StringRegExpReplace($sString, "(?m)\Q" & $aWords[$i] & "\E", "") Next ConsoleWrite("After : " & @CRLF & $sString & @CRLF & @CRLF) The problem is : If "word" was replaced by "" in one pass, StringReplace will not find the search string "more words" in a following pass, because "word" has already been replaced. pixelsearch 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
dersiniar Posted April 22, 2022 Author Share Posted April 22, 2022 17 hours ago, Musashi said: Example : Local $aWords[4] = [3, "word", "/>", "more words"] Local $sString = "In the beginning was the word." & @CRLF & _ "After the word, there were more words, e.g. />" & @CRLF & _ "Now they are gone !" ConsoleWrite("Before : " & @CRLF & $sString & @CRLF & @CRLF) For $i = 1 To $aWords[0] $sString = StringReplace($sString, $aWords[$i], "") ; or use : ; $sString = StringRegExpReplace($sString, "(?m)\Q" & $aWords[$i] & "\E", "") Next ConsoleWrite("After : " & @CRLF & $sString & @CRLF & @CRLF) The problem is : If "word" was replaced by "" in one pass, StringReplace will not find the search string "more words" in a following pass, because "word" has already been replaced. Thank you man, ill tray to add it into my code asap. Looks promising Link to comment Share on other sites More sharing options...
Subz Posted April 22, 2022 Share Posted April 22, 2022 As mentioned above you can use StringRegExpReplace example: Local $aWords[4] = [3, "word", "/>", "more words"] Local $sString = "In the beginning was the word." & @CRLF & _ "After the word, there were more words, e.g. />" & @CRLF & _ "Now they are gone !" ConsoleWrite("Before : " & @CRLF & $sString & @CRLF & @CRLF) $sString = StringRegExpReplace($sString, $aWords[1] & '|' & $aWords[2] & '|' & $aWords[3] , "") ConsoleWrite("After : " & @CRLF & $sString & @CRLF & @CRLF) 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