Jump to content
Developer Wiki and Function Reference Links ×

Issue with repeating substrings in "Strip" Node


HebHeb

Recommended Posts

hey there,

 

can someone explain how I could use the Strip Node whilst using repeating "sub-parts" of the"substring

example:
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)

 

grafik.thumb.png.c1af0d4ee9681b4b25febe86560045dd.png

Anyone? Cheers!

Link to comment
  • Marionette Maven

@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.

  • Like 1
Link to comment

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.

 

grafik.png.621552478257608550ff3bb80c8f75d2.png

 

Regards,

Letti

  • Love 1
Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...