I am trying to figure out an alternative way to go about a couple of depreciated python string functions: string.find() and string.replace(). But from reading about string methods in that link, I can’t figure out a way to do that. Any ideas?
Thanks Dimitar, I thought I tried exactly that but it didn’t work. I didn’t realize you have to format string first (At least according to Visual Codes Intelisense) Now my code does not give me any errors, but still does not work.
inputString = IN[0]
outputString = "{}".format(inputString)
outputString.replace("Hello","Goodbye")
OUT = outputString
It worked! For some reason the second code did not work for me, and gave no errors. But I can work with the first one for now. Will come back to it later, LOL
Here is the syntax for find too in case some one looks for it.
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import TaskDialog
# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
# Place your code below this line
import sys
pyt_path = r'C:\\Program Files (x86)\\IronPython 2.7\\Lib'
sys.path.append(pyt_path)
import string
inputString = IN[0]
result = string.find( inputString, "World") # -1 = Not Found; # = Location of Character before 'H'
newString = string.replace(inputString, "Hello","Goodbye")
outputString = "Original: {}\nReplace() Result: {}\nFind() Result: {}".format(inputString,newString,result)
# Assign your output to the OUT variable.
OUT = outputString