# Convert Text to Array

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

## Comment viewing options

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.

### .

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...

### Yes - it works in 2014 but

Yes - it works in 2014 but not in 2010.

### .

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

### 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 )

### .

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

### .

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
)```

### Convert Text to Array

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

### ...

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