splice or remove element from array

I have an array of strings How do I remove one of them from the Array.

and I want to remove element 4
words = “here are the words removeme”;
wordlist=Regex.Split(words,“\,”);
wordlist.RemoveAt(4);

//does not work. Th rror is removeat is not a member of string.

Anybody have a solution for doing this?

Thanks,

Dan

Doesn’t regex returns a string, and not an array ?

Edit : I haven’t understood everything, but by looking at that ( Intro to JavaScript | WebReference ), shouldn’t you use // instead of \ ?

words.Split(“,”[0]) or the like and
Regex.Split() seems to return a builtinarray which needs to be converted back into a javascript array to use RemoveAt. But the MSDN .net docs claim that RemoveAt is available for Arrays. So I have no idea why I have to do this.

Eric? Dreamora?

Want to explain.

Why can’t unityscript implement a full javascript. I could avoid 90 percent of these problems.

Dan

The problem is that this code does not have an array. You are just using strings.
To do what I think you want to do:

var words = "here are the words removeme";
var wordlist = new Array();
wordlist = words.Split(" "[0]);
print(wordlist);
wordlist.RemoveAt(4);
print(wordlist);

Returns this:
here,are,the,words,removeme
here,are,the,words

Regex.Split() returns a string, not an array. String.Split() returns an array though, and it worked with Array.RemoveAt() for me just fine.

var words = "here are the words removeme";
var wordlist = new Array();
wordlist = words.Split(" "[0]);
print(wordlist);
wordlist.RemoveAt(4);
print(wordlist);

if you leave out this line
var wordlist=new Array();
it does not work.
If you put it in
both Regex.Split and the other split type work. So there is something about that line that is making it work. Maybe it is typecasting the array from built in to javascript.

Is that what’s going on?

I’m not sure why, but as long as you declare the variable a new array it handles it properly.

edit And I was wrong before when I said that Regex.Split() returns a string, it returns the same as String.Split()

If you initialise the variable using

wordlist = new Array();

…the built-in array returned by the Split function get converted into a JS array automatically. If you assign the Split function’s result directly to a variable, its type gets set to a built-in array. The JS array can vary its length and has a RemoveAt function. The built-in array is of fixed length and has no such function.