From 84dbc9cf3d3c628a9b10298b4ebd5c1572881d47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannik=20R=C3=B6=C3=9Fler?= Date: Sat, 21 Sep 2024 12:17:21 +0200 Subject: [PATCH] Update nodes.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added backward substrings For positive ´length´ values, the method returns a substring from index 0 to length. For negative ´length´ values, the method returns a substring starting from the end of the string, going backwards by the absolute value of length. --- nodes.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nodes.py b/nodes.py index 29f7465..af9444a 100644 --- a/nodes.py +++ b/nodes.py @@ -10,7 +10,7 @@ class SubstringFunction: return { "required": { "text": ('STRING', {"multiline": True}), - "length": ('INT', {"default": 75, "min": 0}) + "length": ('INT', {"default": 75}) } } @@ -23,7 +23,11 @@ class SubstringFunction: if text == "undefined": text = "" - out = text[:length] + if length >= 0: + out = text[:length] + else: + out = text[length:] + return {"ui": {"text": (out,)}, "result": (out,)} NODE_CLASS_MAPPINGS = {