[Closed] String Methods
hey everyone, got stuck with this might be simple one in mxs.
string1= “this is my string”
string2= “this is my string and more string”
” this is my strng” is in both the strings. I want that part gone in string2 and only “and more string”string has to be remained. anyways of doing it ? Thanks
No problem! Out of interest, what’s your background? What are you hoping to achieve in max?
Hi Dave,
I studied Computer Science but I’m now working in the architectural visualisation field. I was hoping to look into Maxscripting and write some basic tools to speed up and automate some processes in our workflow. Hopefully it’ll get to a stage where the scripts will be helpful to everyone in our studio. =)
Thanks Dave! It is rewarding when you see your script working. By the way, you have an impressive website and portfolio!
In the meantime I have a question about structs and evaluating an expression.
Say I have the following:
struct aCollection (name, count)
bottleCollection = aCollection "wineBottles" 10
property = count
print bottleCollection.property
How could I get it to evaluate the last line to read as bottleCollection.count instead of trying to find the member “property”?
Thanks
You could do using the following methods:
property = "count"
-- method 1
val = getProperty bottleCollection property
-- method 2
execute ("val = bottleCollection." +property)
Firstly, define your property count as a string, otherwise it will return the undefined value of an undefined variable count
Then, the first method is the best in this situation. getProperty will return a propety from most objects in max – spheres, controllers, structs, etc. For example:
getProperty $sphere01 "radius" -- the radius of $sphere01
getproperty $[1].modifiers[1] #angle -- the angle of the first modifier in the first object in a selection of 2 or more objects
The second method executes max code, similar to eval() in JavaScript. However, the function executes in, and returns any variables in, global scope. It’s also a slow function, but sometimes the only way to get a job done.
Cheers the for the nice words!
Dave
Thanks once again Dave! I’m surprised at how quick you replied and your answers have been of great help. Thanks once again! =)
substituteString <source_string> <from_string> <to_string> Returns a new string with all occurrences of <from_string> in <source_string> replaced with <to_string>. Available in 3ds Max 2008 and higher
(
string1= "this is my string"
string2= "this is my string and more string"
result = (substituteString string2 (string1 + " ") "")
)