How to convert text "1,3,5-12" to array #(1,3,5,6,7,8,9,10,11,12) ?
Forum topic · General Scripting
Convert Text to Array
By Yog · 2016-02-19
Description
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.
.
miauu · 2016-02-23
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 · 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.
Yog · 2016-02-24
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 · 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"