PDA

View Full Version : Filter String


eddybrown
01-12-2011, 10:48 AM
Hi guys,

I'm trying to knock up a script to rename the beginning of a bitmap from GE_ to GEN_

At the moment I'm using the following script but I realise it will look for all occurances of GE_ so I might get unwanted results for instance if the texture had orange_ in the name it would be renamed.


oldname = filterString CurrentTextureName "GE_"
temp = oldname[1]
for i = 2 to oldname.count do
(
temp = temp + "GEN_" + oldname[i]
)
NewTextureName = temp


I've used this script for changing single characters but never larger strings, however it's not working as I'd expect.

For instance it will change 3_Door_FreezerVRayCompleteMap.tga to 3GEN_DoorGEN_FreezerVRayCompleteMap.tga

I wouldn't expect it to change at all...

Pjanssen
01-12-2011, 12:09 PM
filterString splits the provided string on each occurrence of each character in the token string.

How about something like this?
(
local newTextureName;
if (matchPattern textureName pattern:"GE_*" ignoreCase:false) do
(
newTextureName = "GEN_" + (substring textureName 4 -1);
)
)

eddybrown
01-12-2011, 12:20 PM
Thanks for that, that works perfectly! Cheers, although I used the replace string function rather than substring

NewTextureName = replace CurrentTextureName 1 3 "GEN_"

lo
01-12-2011, 12:22 PM
if (substring oldTexName 1 3) == "_GE" do newTexName = replace oldTexName 1 3 "_GEN"

eddybrown
01-12-2011, 12:25 PM
if (substring oldTexName 1 3) == "_GE" do newTexName = replace oldTexName 1 3 "_GEN"

Doh, I posted my edit before you posted this but that's what I've done thanks!

lo
01-12-2011, 12:35 PM
newTextureName = "GEN_" + (substring textureName 4 -1);


nice, I never realized you could use -1 in a substring to get the remainder.

NoFlame
01-12-2011, 02:21 PM
if you use 3ds Max 2008 and higher. there is another function you can use.

if matchpattern oldTextureName pattern:"GE_*" do
newTextureName = substituteString oldTextureName "GE_" "GEN_"
more clear than using number to replace string.

lo
01-12-2011, 02:34 PM
this would not be correct, as it would turn "GE_ORANGE_1" into "GEN_ORANGEN_1"

NoFlame
01-13-2011, 02:21 AM
this would not be correct, as it would turn "GE_ORANGE_1" into "GEN_ORANGEN_1"
WOW! thanks to point out this.
I think i am just lucky that never get this situation before...

Pjanssen
01-13-2011, 09:07 AM
Just an additional note: to be safe, you should actually check the length of the string before using the substring function. Theoretically, you could get an input with less than 4 characters, which will cause a crash.

lo
01-13-2011, 09:47 AM
Just an additional note: to be safe, you should actually check the length of the string before using the substring function. Theoretically, you could get an input with less than 4 characters, which will cause a crash.
How does it cause a crash? It just returns an empty string, which would return false on the == "GE_" condition, as expected.

Pjanssen
01-14-2011, 11:35 AM
How does it cause a crash? It just returns an empty string, which would return false on the == "GE_" condition, as expected.
Ah yes you're absolutely right. So my previous comment can be ignored ;)
I must have been confused with some other language there..

CGTalk Moderation
01-14-2011, 11:35 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.