I am having a difficult time initializing an array of char to use in String.Trim member function in Unityscript. At a high level I am just trying to remove any trailing carriage returns from a string. This should be a no brainer but I have tried different methods to no avail -

for example this -

var charsToTrim : char = [’
‘,’\r’];
chatTextAreaString.Trim(charsToTrim);

results in this error - Assets/Scripts/GameGUI.js(300,60): BCE0022: Cannot convert 'String[]' to 'char[]'.

and this - var charsToTrim : char[] = new char[1]; charsToTrim[1] = ' '; chatTextAreaString.Trim(charsToTrim);

results in this error - Assets/Scripts/GameGUI.js(261,50): BCE0022: Cannot convert 'String' to 'char'.

The root of the issue is that I need to understand the syntax and caveats of using different types of arrays in Unityscript and haven't found a comprehensive source for this.

Any help with my immediate problem would be appreciated and if anyone has a source where I can read up on Unityscript array syntax would also be great.

I think its got something to do with Javascript not liking character literals. Try:

var charsToTrim : char[] = ["
"[0],"\r"[0]]; chatTextAreaString.Trim(charsToTrim);

instead.

`[' ','\r']` is an array of strings. In JS, `'` and `"` are the same. If you want a char, you need to specify one element from a string, such as `" "[0]`. (If the string is one character long, then 0 is of course the only index that will work.)