arrays

How to search a list in C#

Hi there, I have a list like so: List<string[]> countryList and each element of the string array is another array with 3 elements. So countryList[0] might contain the array: new string[3] { "GB", "United Kingdom", "United Kingdom" }; How can I search countryList for a specific array e.g. how to search countryList for new string...

How can i delete a item from an array (vb.net)?

hello, how can i delete a item from an array (vb.net)? thanks ...

PHP, recursive extract of all arrays in multidimensional array to one flat "holder" array ?

I have a messy tree multidimensional array that I want to do the following to: Extract each array, no matter how far nested down to put it into a single "holder array", so this (just a basic example as it would be much more complex than this as far as the nesting) $this = array[0]=> (array[1]=>('a','b'), array[2]=>(...

Unable to return collections or arrays from JAX-WS Web Service

I found that I was unable to return collections from my JAX-WS Web Service. I appreciate that the Java Collections API may not be supported by all clients, so I switched to return an array, but I can't seem to do this either. I've set up my web service as follows: @WebService public class MyClass { public ReturnClass[] getArrayOfStu...

Sorting arrays of paired numbers and removing duplicates or overlaps?

How can I sort two arrays of coordinates in numerical order by the start coordinates e.g. my @starts = (100,100,200,300,400,500,525); my @ends = (150,125,250,350,450,550,550); but choose the biggest difference if there are two matching in either the starts or ends list? E.g. my @uniq_starts = (100,200,300,400,500); my @unique_ends ...

Check and return duplicates array php

Hello, I would like to check if my array has any duplicates and return the duplicated values in an array. I want this to be as efficient as possible. Example :$array = array(1,2,2,4,5) function returndup($array) should return 2 ; if array is array(1,2,1,2,5); it should return an array with 1,2 Also the initial array is always 5 posit...

Why can Array.Length and Array.Count() not be assigned to const values?

I wanted to follow some excellent C++ advice of calculating the array length once and then using a value without having to call a function like so: Instead of: for( int i = 0; i < arr.length; ++i ) I write const int size = arr.length; // or arr.Count() for( int i = 0; i < size; ++i ) After reading a different thread (Is it costly ...

beginner's question: copying certain elements of an array

I am trying to copy certain elements of an array into another. For example, I want to copy index 0 of lines into index 0 of links, index 3 of lines into index 1 of links, and so on (every 3 element of lines basically basically). What I have so far keeps getting me an ArrayIndexOutOfBound error. Thank you for your help! String[] lines =...

Can a JavaScript variable be used in plain HTML? ** EDIT

What I mean is, can a variable/array declared and initialized be used in HTML, outside the <script>-tags? Fx. <script type="text/javascript"> var foo = array('placeholder1', 'placeholder2'); </script> <body> <p><!--access the variable here-->foo[0]</p> </body> How do you access the variable/array in this case? like this: <p><script ...

In perl, checking an array for a value and removing it if exists for each value of another array

Basically, I have an array, let's say @badvalues. I have another array, let's say @values. Basically, I want this: For each element in @badvalues See if it is in @values If it is, delete it Ultimately, I should end up with either the array @values, containing no elements that are in the array @badvalues, or a new array, @goodvalues,...

Using Array.BinarySearch() to return first value <= lookup value ?

I'm trying to create a "lookup" column that would return the index of the array value that is equal to or less than the value being looked up. So this is my attempt, which seems to work fine, but I was wondering if there is a cleaner way of doing it ? // Sorted float[] ranges = new float[] { 0.8f, 1.1f, 2.7f, 3.9f,...

Dynamic arrays in VBScript with Split(). Is there a better way?

Hi, all! A lot of the scripts I write at my job depend on the creation of dynamically-sizable arrays. Arrays in VBScript make this a pretty arduous task, as one has to Redim arrays every time one wants to resize them. To work around this, I've started making comma-delimited strings and using Split(...) to create 1D arrays out of it. Wh...

Why do array[n] and array[x] where x=n return different values?

Does anyone know what may cause the read-back values of array[n] and array[x] (x=n) different from each other? EDIT: Following is a compilable code to illustrate the problem I encountered. If you run the following code, you won't see any problem. I am just using it to describe the problem I saw in my original program which is a simulato...

Diff function on two arrays, in c++/mfc/stl?

Diff function on two arrays (or how to turn Old into New) Example One[]={2,3,4,5,6,7} Two[]={1,2,3,5,5,5,9} Example Result Diff: insert 1 into One[0], One[]={1,2,3,4,5,6,7} Diff: delete 4 from One[3], One[]={1,2,3,5,6,7} Diff: modify 6 into 5 in One[4], One[]={1,2,3,5,5,7} Diff: modify 7 into 5 in One[5], One[]={1,2,3,5,5,5} Diff: app...

In C++, what happens when the delete operator is called?

In C++, I understand that the delete operator, when used with an array, 'destroys' it, freeing the memory it used. But what happens when this is done? I figured my program would just mark off the relevant part of the heap being freed for re-usage, and continue on. But I noticed that also, the first element of the array is set to null,...

"asdf".Length > 0 vs. "asdf".Any()?

How is an arrays Length property identified, by an internal variable (i.e. m_Length) or it's gonna enumerate thru all the items of the array. The difference takes place if I want to check whether an array contains any elements. Dim asdf = { "a"c, "s"c, "d"c, "f"c } Dim any = asdf.Any() Dim any2 = asdf.Length > 0 (Also note that Any i...

Get a subset of an array based on an array of keys

I wrote this function to get a subset of an array. Does php have a built in function for this. I can't find one in the docs. Seems like a waste if I'm reinventing the wheel. function array_subset($array, $keys) { $result = array(); foreach($keys as $key){ $result[$key] = $array[$key]; } return $result; } ...

JavaScript looping through an object while adding items

I have the following code segment: var run = 0; var obj = {'item1':0,'item2':5,'item3':10}; for (var i in obj){ run++ obj['newItem'+run] = 5; } return run; and it returns 3. But I want it to go on infinitely and eventually crash the browser. Is there any way of updating the obj variable while in a for loop? ...

Why does a pointer's allocated memory persist after a function, but not an array?

So, I ask this question in the context of a basic text input function I see in a C++ book: char *getString() { char temp[80]; cin >> temp; char * pn = new char[strlen(temp + 1)]; strcpy(pn, temp); return pn; } So temp declares an array of 80 chars, an automatic variable whose memory will be freed once getString() r...

Java Hashmap values to Array

I have the following code which adds some arrays to a hashmap but then I want access those arrays to do some work on them later. I've gotten this far but can't figure the rest out to make it work.... import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; public static void main(String[] args) { St...