ScriptSpot

Forum topic · General Scripting

Convert Text to Array

By Yog · 2016-02-19

Description

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

Comments (9)

Yog · 2016-02-23

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.

Yog · 2016-02-24

Yes - it works in 2014 but not in 2010.

.

miauu · 2016-02-24

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

.

miauu · 2016-02-24

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

.

miauu · 2016-02-23

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

Yog · 2016-02-19

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

barigazy · 2016-02-23

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"