Hey guys.
I’m having a bit of trouble with finding the position of a string in an array using JScript. Whats the best way to go about this?
I know what the strings are but I need to know what the positions of them are.
Cheers.
Hey guys.
I’m having a bit of trouble with finding the position of a string in an array using JScript. Whats the best way to go about this?
I know what the strings are but I need to know what the positions of them are.
Cheers.
Loop through the array.
for(int i = 0; i < array.Length; i++)
{
Debug.Log("The element in index " + i + " is " + array[i]);
}
I think that should about do it.
Here is my example, hope this helps someone:
It’s a rough snippet of something I’m working on.
public string[][] pass = new string[2][];
// define the array somewhere like:
pass[0] = new string[] { "ant", "bug" };
pass[1] = new string[] { "dog", "boy" };
// check for what's in the list
void checkPassword(string k)
{
int i = 0;
int l = pass[0].Lenth;
for(i=0; i < l; i++) // don't define vars in your for() it's slow
{
if(pass[0] == k) { print("index --> " + i); }
}
}