arrays

Arrays & Pointers

Hi, Looking for some help with arrays and pointers and explanation of what I am trying to do. I want to create a new array on the heap of type Foo* so that I may later assign objects that have been created else where to this array. I am having troubles understanding what I am creating exactly when I do something like the following. Foo...

Simplest way to match array of strings to search in perl?

What I want to do is check an array of strings against my search string and get the corresponding key so I can store it. Is there a magical way of doing this with Perl, or am I doomed to using a loop? If so, what is the most efficient way to do this? I'm relatively new to Perl (I've only written 2 other scripts), so I don't know a lot o...

Convert between python array and .NET Array

I have a python method that returns a Python byte array.array('c'). Now, I want to copy this array using System.Runtime.InteropServices.Marshal.Copy. This method however expects a .NET array. import array from System.Runtime.InteropServices import Marshal bytes = array.array('c') bytes.append('a') bytes.append('b') bytes.append('c') M...

Flipping an image using a one dimensional array of characters.

I have the data of an image loaded into memory as a one dimensional array. Since I'm trying to use OpenGL to draw it, and since it reads from the bottom up, I want to try and flip the elements of the array before they're sent to OpenGL. Maybe there's a way to tell OpenGL to read from the top to the bottom? Anyways, I tried using a few me...

Objective-C initial values of created C-array

I create an array, similar to classic C (not NSArray or one of it's children) - something like BOOL i[5];. And I want to make all its values to be equal to NO. First of all, I didn't found any information about initial values of such arrays (I know that in classic C they will be undefined, but don't know exactly about Objective-C. I fou...

[JavaScript] Function making a slight miscalculation.

Hi, To begin with, I have a database that holds map data for a game I am creating. A script on my page uses JSON to retrieve a certain amount of that data from the database and store it in an array. When the data is retrieved it goes through a function that finds out how many individual tiles are used in that particular area. Here is t...

Capture String from Array

I'm trying to figure out how to get a string from an array starting at some given position. Say we have an array that's arbitrarily long and my string starts at location 1000. If I wanted to get a string from a file I would simply use something like getc or scanf or something. How do I carry out these same functions on an array instead o...

Javscript Loop / Array / Variable question

Hi. I'm trying to get this to work and I hope this isn't too vague. -Chris var example = new Array(); var test1 = "one"; var test2 = "two"; var test3 = "three"; for (v = 1; v <= 3; v++) { alert(example[test + v]) } I want the alert to say: one two three ...

Get the final key of an array in PHP

I have a standard associative array in PHP. what's the simplest way to get the last key in that array? example: $foo = array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'); and i would like to get 'key3'; ...

Flash AS3 button eventlistener array bug

Hi there, this is my first time posting a question here. I have an array of 12 buttons on a timeline that when first visiting that part of the timeline, get a CLICK eventlistener added to them using a for loop. All of them work perfectly at that point. When you click one it plays a frame label inside the specific movieClip and reveals...

Is it correct to use Array.CopyTo to copy elements or should a for-loop always be used?

It's easier to write intArray1.CopyTo( intArray2, 0 ) than the for-loop equivalent, but System.Array does not provide any generic Copy/CopyTo methods. Is it better to write the for-loop? Or is using Copy/CopyTo compiled or JIT'd efficiently enough? ...

Sorting an array in PHP based on different values

I have an array whose elements are name, reversed_name, first_initial and second_initial. A typical row is "Aaron Smith", "Smith, Aaron", "a", "s". Each row in the array has a first_initial or second_initial value of "a". I need to display the rows alphabetically but based on the "a" part, so that either the name or reversed_name will b...

How can use foreach to Loop Through PHP Array

How can use foreach loop to loop through the $Result? <?php mysql_connect("localhost", "mysql_user", "mysql_password") or die("Could not connect: " . mysql_error()); mysql_select_db("mydb"); $Query = mysql_query("SELECT * FROM mytable"); $Result = array( ); while ($Row = mysql_fetch_array ( $Query) ) { $Result [ ] = $Row; } m...

preg_replace replacing with array

What I want to do is replace the "[replace]" in input string with the corresponding vaule in the replace array. The total number of values will change but there will always be the same number in the replace array as in input string. I have tried doing this with preg_replace and preg_replace_callback but I can't get the pattern right for ...

Why, in Ruby, does Array("foo\nbar") == ["foo\n", "bar"]?

In Ruby 1.8.7, Array("hello\nhello") gives you ["hello\n", "hello"]. This does two things that I don't expect: It splits the string on newlines. I'd expect it simply to give me an array with the string I pass in as its single element without modifying the data I pass in. Even if you accept that it's reasonable to split a string when pa...

How can i create array of my class with default constructor ?

Hello For example MYCLASS[] myclass = new MYCLASS[10]; Now myclass array is all null array but i want to have default constructed Array .I know that i can write loops for set default constructed but i am looking for more easy and simple way. ...

Visually Viewing and Editing a Two-Dimensional Array - VB/C#

I've never personally used any of the Data controls within Visual Studio. I need to view and edit a two-dimensional byte array, 16x15 objects. Is there any control capable of editing this information? I've tried to access data with the DataViewGrid, but am not sure how to use it. It would be great to edit this information via rows and...

remove duplicates from object array data java

hi i want to know how to remove duplicates in object. for example cat c[] = new cat[10]; c[1].data = "ji"; c[2].data = "pi"; c[3].data = "ji"; c[4].data = "lp"; c[5].data = "ji"; c[6].data = "pi"; c[7].data = "jis"; c[8].data = "lp"; c[9].data = "js"; c[10].data = "psi"; i would like to remove the duplicates value from object ar...

design decision between array or object save in database

i code some configuration setting. And need those values to be load, everytime my webapp start. yes, it's somekind autoload setting. But, right now, i have to choose between save it as object or array. is there any different between them when we save them in database ? which one is faster or maintainable or other pro and cons thanks ...

Is the following array really multidimensional?

Book I’ learning from claims that intArray has two dimensions. But since calling intArray.GetLength(1) will result in an IndexoutOfRange exception, couldn’t we claim that unlike rectangular arrays, intArray isn’t really multidimensional and thus has only one dimension? int[][] intArray=new int[3][]; thank you EDIT: BTW - I understan...