Convert Text to Array

How to convert text "1,3,5-12" to array #(1,3,5,6,7,8,9,10,11,12) ?

Comments

Comment viewing options

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

barigazy, your code works

barigazy, your code works well - Thanks!

miauu, does not works correct. We have only #(1, 3, 5, 15, 18, 22). String "-" doesnot want converted to "..", it converts only to "." , because it increase string.count in cycle.

miauu's picture

.

I wrote my code using 3dsMax 2014 and it works correctly.
Watch the video: https://dl.dropboxusercontent.com/u/53119355/Other_Videos/Str_To_Array_v...

Yog's picture

Yes - it works in 2014 but

Yes - it works in 2014 but not in 2010.

miauu's picture

.

Yep. In 3dsMax 2010 it not works. AD should tells why.

Yog's picture

and it is interesting..for

and it is interesting..for example in this theme: http://www.scriptspot.com/forums/3ds-max/general-scripting/extrude-not-w... i have opposite problem - in 2010 works well, in 2013 - not works extrude with spinner correctly )

miauu's picture

.

As one friend of mine said once - "this is max my friend, this is max"
:)

miauu's picture

.

Am ugly solution :)

(
	str = "1,3,5-12,15,18,22-25"
	for s = 1 to str.count where str[s] == "-" do str[s] = ".."	
	str = "#{" + str + "}"
	arrayVal = (execute str) as array
)
Yog's picture

Convert Text to Array

How to convert text "1,3,5-12" to array #(1,3,5,6,7,8,9,10,11,12) ?

barigazy's picture

...

Try with this function

fn convertStringToArray string =
(
	array = #()
	if (numA = filterstring string ",").count > 1 do
	(
		for i in numA do
		(
			if (e = i as number) != undefined then append array e else
			(
				if (numB = filterstring i "-").count == 2 do
				(
					if (f = numB[1] as number) != undefined and (s = numB[2] as number) != undefined do
					(	
						for j = f to s do append array j
					)
				)
			)
		)
	) ; array
)
convertStringToArray "1, 3, 5-12, 21-23"

bga

Comment viewing options

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