HebHeb Posted August 28, 2023 Share Posted August 28, 2023 hey there, can someone explain how I could use the Strip Node whilst using repeating "sub-parts" of the"substringexample: string Input is: TestStringStripFriend-From Test ("From" should stay) Strip Operator is: TestStringStripFriend- result is: om Test ("From" should stay) result should be:From Test ("From" should stay) Anyone? Cheers! Quote Link to comment
Marionette Maven Marissa Farrell Posted August 28, 2023 Marionette Maven Share Posted August 28, 2023 @HebHeb It appears this is happening because it's counting the "Fr" in From and not just Friend, if you change the capitalization to lowercase for "from" then it works. I'm looking into this, the strip function is built-in for Python, so we don't do the handling for it within this node, but maybe there's something we can do to add our own handling. Edit: Here's a post about how the Python "strip" function works:https://stackoverflow.com/questions/1687171/why-does-str-lstrip-strip-an-extra-character I'll think about how we can get around this limitation. In the meantime, I would suggest using the Replace String node with an empty string as the input for sNew. 1 Quote Link to comment
Letti R Posted August 29, 2023 Share Posted August 29, 2023 Hello, you may want to use. string.removeprefix("") string.removesuffix("") These functions seem to do what you are searching for. A Marionette node with the functions above could look like this: @Marionette.NodeDefinition class Params(metaclass = Marionette.OrderedClass): #APPEARANCE #Name this = Marionette.Node( "remove suffix prefix" ) this.SetDescription('Removes the suffix or the prefix from the full string.') #Input Ports s = Marionette.PortIn( '', 's' ) s.SetDescription('The full string.') s2 = Marionette.PortIn( '', 'sSub') s2.SetDescription('The substring.') #OIP Controls pos = ['left', 'right', 'both'] position = Marionette.OIPControl( 'Position', Marionette.WidgetType.RadioButton, 0, pos) position.SetDescription('an OIP control representing the position options for where the string gets stripped.') #Output Ports outList = Marionette.PortOut('sNew') outList.SetDescription('The stripped string.') #BEHAVIOR def RunNode(self): #inputs s = self.Params.s.value s2 = self.Params.s2.value pos = self.Params.pos position = self.Params.position.value #script if pos[position] == 'left': sNew = s.removeprefix(s2) elif pos[position] == 'right': sNew = s.removesuffix(s2) elif pos[position] == 'both': sNew = s.removeprefix(s2).removesuffix(s2) #outputs self.Params.outList.value = sNew You can create the node by replacing the code of any Marionette node with the code above. Regards, Letti 1 Quote Link to comment
Antonio Landsberger Posted August 29, 2023 Share Posted August 29, 2023 @Marissa Farrell Perhaps this node could be improved by introducing an OIP option that can be toggled (preferably two radio buttons) that lets the user choose which behaviour they wish for. 1 Quote Link to comment
HebHeb Posted August 29, 2023 Author Share Posted August 29, 2023 Thank u! The solution suggested by @Letti R works! Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.