Notifications
Clear all

[Closed] parsed string problems

got a problem i’m going to throw out, and see if anyone can help me. I’m parsing a file name out to get some info stored in the name, then trying to rebuild the name without the aforementioned info. so something along the lines of

filterstring “blah_animation5_f5-f20.max” “_”
–> #(blah, animation5, f5-f20)

now i need to take everything in the array but the last entry and rebuild it to blah_animation.max.

I think i need to build a loop that recursively adds the array entries to the last one, but i’m not sure how.
something like

for i = 1 to (array.count-1)
append array.[i] “_”

but that will only get me “blah_” and “animation_”

I’m not sure where to go from there. any help?

thanks!

4 Replies
1 Reply
(@denist)
Joined: 10 months ago

Posts: 0

fn parseAnimFilename filename = 
(
	file = getfilenamefile filename
	type = getfilenametype filename
	ss = filterstring file "_"
	range_part = ss[ss.count]
	anim_part = ss[ss.count-1]

	frames = filterstring range_part "f-"
	range = interval (frames[1] as time) (frames[2] as time) 
	
	anim_str = trimright anim_part "0123456789"
	anim_id = (substring anim_part (anim_str.count+1) -1) as integer 
	str = substring file 1 (file.count-range_part.count)
	str = trimright str "_0123456789"
	file = str + type
	format "	file: %
	anim: %
	time: %
" file anim_id range
--	file
	ok
)
parseAnimFilename "blah_animation5_f5-f20.max"
/*
-- result:
	file: blah_animation.max
	anim: 5
	time: (interval 5f 20f)
*/

You could try rebuilding the string like this:
EDIT: oops just noticed you didn’t want the last value

(
	  strSplit = filterstring "blah_animation5_f5-f20.max" "_"
	  newStr = ""
	  
	  for x in 1 to (strSplit.count-1) do
	  (
		  newStr += strSplit[x]
		  if x < (strSplit.count-1) do newStr += "_"
	  )
	  
	  print newStr
)

or maybe something a little shorter:

(
	strSplit = filterstring "blah_animation5_f5-f20.max" "_"
	newStr = ""
	
	for x in 1 to strSplit.count where x < (strSplit.count-1) do newStr += (strSplit[x] + "_")
	newStr += strSplit[(strSplit.count-1)]
	
	print newStr
)

awesome. that works perfectly. I had no idea i could perform a += operation on string variables. the more you know…

thanks a ton jason!

-ian

(
	strSplit = filterstring "blah_animation5_f5-f20.max" "_"
	newStr = strSplit[1]
	for i = 2 to (strSplit.count - 1) do (newStr += ("_" +strSplit[i]))
	print newStr
)

One-upped!