Making an String out of all Array Members - Maxscript


#1

Moin,
Im stuck with some simple problem but i cant really wrap my head around it. In my Function i collect all Letters of a String till it maches a specific letter and append them to an array. Im pretty sure thats not how it should be done (propably with matchPattern) . Anyways when i now try to convert my Array to a string by: array as string or a for loop like that:

fn makeArrayToSting arrayX = (

stringM = ""

for element in arrayX do (
	
	stringM = stringM + (element as string)
	) 
	
return stringM

)

i only get glibberish. And not my Word. Im pretty sure there is an simple solution for this but i also would love to know what exactly is the Problem with my Approach. And if there are easy solutions to reverse an String or Array would be good too know too (Right now i feed them in another rray with an For loop in the other direction).

Idears would be Appreciated
Greeting Eli


#2

Only to make it clear my ArrayX is for example = (“A”,“L”,“F”)


#3

arrayA = #(“A”,“L”,“F”) – any array
var= “” --empty variable

– concatenate array items with the character ; and a space in between
for i in arrayA do (
var = var + i + "; "
)

var – resulting string


#4

there’s no any super-cool and fancy in MaxScript to do the job… so the break and make string functions might look like this:

fn break_string str = 
(
	for k=1 to str.count collect str[k]
)
fn combine_chars arr = 
(
	str = ""
	for c in arr do str += c
	str
)

str = "how to break and make string?"
arr = break_string str
str = combine_chars arr

#5

Convert a string to an array of characters:

fn StringToCharArray str = (dotnetobject "system.string" str).ToCharArray()

Convert an array of characters to string:

fn CharArrayToString arr = (dotnetobject "system.string" arr).ToString()

or

fn CharArrayToString arr =
(
	str = stringstream ""
	for j in arr do format j to:str
	str as string
)

Split a string by a given character and return the first match:

fn SplitStringByChar str char:"" = (filterstring str char)[1]

Example:

str = "Im stuck with some simple problem but i cant really wrap my head around it. In my Function i collect"

arr = StringToCharArray str
str = CharArrayToString arr

SplitStringByChar str char:"."

#6
(
	str   = "string to reverse"
	chars = (dotnetobject "system.string" str).ToCharArray asdotnetobject:true
	(dotnetclass "system.array").Reverse chars
	(dotnetobject "system.string" chars).ToString()
)

#7

if we have started to consider all the possibilities:

py = python.import "__builtin__" 

str = "Im stuck with some simple problem but i cant really wrap my head around it. In my Function i collect"

cc = py.list str as array
py.unicode.join "" cc

cp = py.unicode.split str as array
py.unicode.join " " cp

cc = py.list str
cc.reverse()
py.unicode.join "" cc

:sunglasses: