ScriptSpot

Forum topic · Scripts Wanted

String

By chrrox · 2009-10-03

Description

Can anyone tell me how to manipulate a string so I can add or remove parts of that string.

What I want to do is I import a mesh into max say test.obj
it is located in c:\test\test.obj
I want to be able to isolate it so I just have the word test.obj
and then once I have that rename it so I can create a texture name test.dds
and then assign it to that object.
I think I can assign it to the object ok but I have no idea how to go about manipulating the name like that.
If its not a lot of extra work could you show how to add _s or _n or anything after the name but before the extension so I could get test_n.dds and test_s.dds

Thanks a lot in advance :)

Comments (2)

chrrox · 2009-10-04

Thanks for this great code this was exactly what I was looking for.

real08121985 · 2009-10-04

Take a look at the maxscript reference at "File Name Parsing".
for example:

s = "c:\\test\\test.obj" -- your string
t = getFilenameType s -- returns the type "obj"
p = getFilenamePath s -- return the path "c:\\test\\"
f = getFilenameFile s -- return the file "test"

x = f + "_n." + t -- returns "test_n.obj"