incremental renaming - get unique name

I think this is very simple, but I don't know how to do it!

let's say I have array A which contains unique names!

when I want to rename element i.name I want to add automatically a number - 01, 02 and so on!

let's say I have

"element" - > after renaming I should get "element_01"
"element_01" - > after renaming I should get "element_02"
and so on!

Except this I should everytime check:

if (finditem A "element_01" == 0) then
i.name = "element_01"
else
i.name = incrementfn "element_01"

append A i.name

Comments

Comment viewing options

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

solved

finished!

artrender.info's picture

here is the idea

global allnames
fn incrementfn old_name =
(
	--check if name end conains digits -- if yes then 
		tryname = (substituteString old_name digits) + "_" + ((digits as integer + 1) as string)
	if (finditem allnames tryname == 0) then
		tryname
	else incrementfn tryname
)
 
 
i.name = incrementfn i.name 

Comment viewing options

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