arrays

Algorithm for joining e.g. an array of strings

I have wondered for some time, what a nice, clean solution for joining an array of strings might look like. Example: I have ["Alpha, "Beta", "Gamma"] and want to join the strings into one, separated by commas – "Alpha, Beta, Gamma". Now I know that most programming languages offer some kind of join method for this. I just wonder how the...

Merging two arrays in .Net

Is there a built in function in .Net 2.0 that will take two arrays and merge them into one array? The arrays are both of the same type. I'm getting these arrays from a widely used function within my code base and can't modify the function to return the data in a different format. I'm looking to avoid writing my own function to accomplis...

Storing multiple arrays in Python

I am writing a program to simulate the actual polling data companies like Gallup or Rasmussen publish daily: www.gallup.com and www.rassmussenreports.com I'm using a brute force method, where the computer generates some random daily polling data and then calculates three day averages to see if the average of the random data matches poll...

Getting the array key in a foreach loop

Bear in mind I'm very new to C#. I'm trying to get the key of the current element in a foreach loop. I know how to do this in PHP but I'm clueless with C#. For example: foreach($array as $key => $value) { echo("$value is assigned to key: $key"); } What I'm trying to do in C#: int[] values = { 5, 14, 29, 49, 99, 150, 999 }; fo...

How to work around a very large 2d array in C++

I need to create a 2D int array of size 800x800. But doing so creates a stack overflow (ha ha). I'm new to C++, so should I do something like a vector of vectors? And just encapsulate the 2d array into a class? Specifically, this array is my zbuffer in a graphics program. I need to store a z value for every pixel on the screen (henc...

Rosetta Stone - Sorting Arrays

I thought I would pose a question I'm describing as a "Rosetta Stone". That is to say, I am posing a question, and would like to see answers given for a number of different languages so that someone moving from one language to another can see how some typical operation is done. I have always found these types of comparisons to be very ...

Three dimensional arrays of integers in C++

Hi, I would like to find out safe ways of implementing three dimensional arrays of integers in C++, using pointer arithmetic / dynamic memory allocation, or, alternatively using STL techniques such as vectors. Essentially I want my integer array dimensions to look like: [ x ][ y ][ z ] x and y are in the range 20-6000 z is known and ...

Making a PHP object behave like an array?

I'd like to be able to write a PHP class that behaves like an array and uses normal array syntax for getting & setting. For example (where Foo is a PHP class of my making): $foo = new Foo(); $foo['fooKey'] = 'foo value'; echo $foo['fooKey']; I know that PHP has the _get and _set magic methods but those don't let you use array notat...

PHP: Can I reference a single member of an array that is returned by a function ?

Hi - any idea how if the following is possible in PHP as a single line ?: <?php $firstElement = functionThatReturnsAnArray()[0]; ... It doesn't seem to 'take'. I need to do this as a 2-stepper: <?php $allElements = functionThatReturnsAnArray(); $firstElement = $allElements[0]; ... just curious - other languages I play with allow th...

How/When to abandon the use of Arrays in c#.net?

I've always been told that adding an element to an array happens like this: An empty copy of the array+1element is created and then the data from the original array is copied into it then the new data for the new element is then loaded If this is true, then using an array within a scenario that requires a lot of element act...

Computationally efficient three dimensional arrays in C

I am trying to solve numerically a set of partial differential equations in three dimensions. In each of the equations the next value of the unknown in a point depends on the current value of each unknown in the closest points. To write an efficient code I need to keep the points close in the three dimensions close in the (one-dimension...

Extending/Merging VB Arrays

I have a class with a public array of byte(). Lets say its Public myBuff as byte() Events within the class get chunks of data in byte() array. How do i tell the event code to stick the get chunk on the end. Lets say Private Sub GetChunk Dim chunk as byte ... get stuff in chunk Me.myBuff += chunk (stick chunk on end of public array ...

How to instantiate a Java array given an array type at runtime?

In the Java collections framework, the Collection interface declares the following method: T[] toArray(T[] a) "Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a ne...

How to concatenate two arrays in Java?

I need to concatenate two String arrays in Java. void f(String[] first, String[] second) { String[] both = ??? } What is the easiest way to do this? ...

Initializing an array on arbitrary starting index in c#

Is it possible in c# to initialize an array in, for example, subindex 1? I'm working with Office interop, and every property is an object array that starts in 1 (I assume it was originally programed in VB.NET), and you cannot modify it, you have to set the entire array for it to accept the changes. As a workaround I am cloning the orig...

How can I get the unique values of an array in .net?

Say I've got this array: MyArray(0)="aaa" MyArray(1)="bbb" MyArray(2)="aaa" Is there a .net function which can give me the unique values? I would like something like this as an output of the function: OutputArray(0)="aaa" OutputArray(1)="bbb" ...

Php $_GET issue

foreach ($_GET as $field => $label) { $datarray[]=$_GET[$field]; echo "$_GET[$field]"; echo "<br>"; } print_r($datarray); This is the output I am getting. I see the data is there in datarray but when I echo $_GET[$field] I only get "Array" But print_r($datarray) prints all the data. Any idea how I pull those values? OU...

How do I efficiently search an array to fill in form fields?

I am looking for an efficient way to pull the data I want out of an array called $submission_info so I can easily auto-fill my form fields. The array size is about 120. I want to find the field name and extract the content. In this case, the field name is loanOfficer and the content is John Doe. Output of Print_r($submission_info[1]): ...

Converting std::vector<>::iterator to .NET interface in C++/CLI

I am wrapping a native C++ class, which has the following methods: class Native { public: class Local { std::string m_Str; int m_Int; }; typedef std::vector<Local> LocalVec; typedef LocalVec::iterator LocalIter; LocalIter BeginLocals(); LocalIter EndLocals(); private: LocalV...

php $_GET sort problem

here is the input i am getting from my flash file process.php?Q2=898&Aa=Grade1&Tim=0%3A0%3A12&Q1=908&Bb=lkj&Q4=jhj&Q3=08&Cc=North%20America&Q0=1 and in php i use this code foreach ($_GET as $field => $label) { $datarray[]=$_GET[$field]; echo "$field :"; echo $_GET[$field];; echo "<br>"; i get this out put Q2 :898 Aa :Grade1 ...