Filter String

Filtering a string based on its characters.

I want to filter a string up to _v###

so filter any string up to

"underscore + letter + number + number + number"

obviously this does not work

filterstring donut_Violin_v005_cool "_*###"

which i want to return

"donut_Violin"

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
JokerMartini's picture

Anubis

Thank you anubis for the checking of the script and modifying it to work properly.

The reason we put v into the version number because it helps distinguish the file version number versus the shot number.

For example if we are doing a short and there are 100 shots.

Shot001_v001.max

Sometimes if a shot is added after the fact it then is written in as

Shot001_02_v001.max

It is a popular way of formatting that I've come across in the industry as well.

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

Anubis's picture

i see...

Yeah, am too seen this naming syntax used in the industry, ever was involved once to debbug such private function library, so i have the chance to see how much this complicate the whole automation. For me, this "v" is a drawback. Even more, base name as "Shot_001" is better than "Shot001". Also i see you add new members to the name-chain, for ex. if there c'd be a member "Shot_001_02__001" then the base name s'd be "Shot_001_00__001" (not "Shot_001__001"). But this a long story and matter of preferences :) Ah, as you see, i insert an example replacement of "v" usage, using "_" instead, so the "_v001" for ex. become "__001".

Ok, i glad to know you have working code ;)

my recent MAXScripts RSS (archive here)

JokerMartini's picture

Agreed

That makes complete sense. Although the naming conventions I've worked with, are not all that great, they do seem to work for the time being.
As for putting an extra "_" for the versioning that is a good idea.
It is something I'll have to keep in mind and possibly try and incorporate.
Thanks for the words Anubis.

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

mjbg's picture

i came with this

i came with this sollution
dont know if this helps
i think it does what you asked..

strName = "donut_Violin_v005_cool"
whereToStop = undefined
 
for o in 1 to strname.count do 
(
if strname[o] == "_" \
and superclassof (execute strname[o+1]) == value \
and superclassof (execute strname[o+2]) == number \
and superclassof (execute strname[o+3]) == number \
and superclassof (execute strname[o+4]) == number \
do whereToStop = (o - 1)
)
 
filteredName = ""
try(for o in 1 to whereToStop do append filteredName strname[o])catch(print "pattern not found")
filteredName
JokerMartini's picture

No, it's just a thing I have

No, it's just a thing I have come across quite a few times where I've needed to filter a string in a specific way and was unsure how to do so.

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

Anubis's picture

fixed

now i found a time to test this and saw i was omit "_".
next should work:

strName = "donut_Violin_v005_cool"
strArr = filterString strName "_"
newName = ""
eofName = false
for str in strArr while not eofName do (
	if str[1] != "v" then newName += "_" + str
	else (
		if trimRight str "0123456789" != "v" then newName += "_" + str
		else eofName = true
	)
	newName = trimLeft newName "_"
)
newName -- "donut_Violin"

meanwhile, just advice, when you design your naming convention, keep in mind all incoming complications. i found as useful to put only digits on the tail, and also not alphabet mixin (like "_v005"), just digits. so if you have a names like "base_name_1_0012" (where "1" is the major version and "0012" minor sub-version) then the whole Filtering is just: trimRight str "_0123456789".

my recent MAXScripts RSS (archive here)

Anubis's picture

is this work?

(not tested)

strName = "donut_Violin_v005_cool"
strArr = filterString strName "_"
newName = ""
eofName = false
for str in strArr while not eofName do (
	if str[1] != "v" then newName += str
	else (
		if trimRight str "0123456789" != "v" then newName += str
		else eofName = true
	)
)

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.