append string

Hi I'm trying to append a string to be just what is within the sq brackets. Is this possible?

dir_array = "V01_test_[bob]_01"
--dir_array = GetDirectories (paths+"\\*")
 
tokens = #()
 
for c = 1 to dir_array.count do (
	folders = filterString dir_array[c] "//" -- e.g. "C:\\Users\\YourName\\Desktop" will yield #("C:", "Users", "YourName", "Desktop")
	append tokens folders[folders.count] -- append last element, which is the subfolder
)--end for
 
try(DestroyDialog Save_Lib)catch()
rollout Save_Lib "Project Manager" width:425 height:173
(
	dropDownList ProjectList "Project" height:99 width:99 pos:[13,70] items:tokens
) createDialog Save_Lib

Comments

Comment viewing options

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

Yes

I'm trying to populate a dropdownlist. Its like I need to select the second one from the end?

Anubis's picture

many ways exists to parse strings in mxs

for example:

str = "V01_test_[bob]_01"
 
-- #1 // using skipToString & Substring:
ss = str as stringStream
skipToString ss "["
p1 = filePos ss
skipToString ss "]"
p2 = filePos ss
close ss
newStr = substring str p1 (p2 - 1 - p1)
 
-- #2 // using findString & Substring:
p1 = findString str "["
p2 = findString str "]"
newStr = substring str (p1 + 1) (p2 - 1 - p1)
 
-- #3 // using filterString:
newStr = (findString str "[]")[2]

my recent MAXScripts RSS (archive here)

barigazy's picture

example

dir_array = "V01_test_[bob]_01"
--"V01_test_[bob]_01"
wordsArr = filterString dir_array "_"
--#("V01", "test", "[bob]", "01")
trimleft (trimright (wordsArr[wordsArr.count-1]) "]") "["
--"bob"

barigazy

barigazy's picture

Are you trying to fill

Are you trying to fill dropdown list with sub-folders names or something else?

barigazy

Comment viewing options

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