arrays

[Python] Open file into array, search for string and return value

Alright, I've been working on this for a while and cannot get it. I'm making a method that accepts a filename, and a pattern. E.g findPattern(fname, pat) Then the goal is to look for that pattern, say the string "apple" within the text file that is opened, and return it's location by [line, beginning character index] I'm new to python...

jQuery For Loop with Post Not Counting Correctly

So, I have the following line of code, that does a for loop and subjects 12 on every loop. If I alert right before the post, it alerts the numbers as you would expect (72, 60, 48, 36, 24). But, with the alert inside the post it alerts the number 12 five times. Any idea why that is? Any idea where the number 12 is coming from? function l...

Rails - Saving Nested Arrays

I was able to create nested arrays in my view to post to my 'create' action. But I'm not sure how to save the nested array. Here's the basic create action where it gets all individual params bunched in mass-assigned params: def create @post = Post.new(params[:mass_assigned]) respond_to do |format| if @post.save format.htm...

Finding Squares in an array

I have an 2 dimensional array that is full of 1s and 0s such as 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 You can see there is a square in th array. I am trying to make a function that will make a rectangle or ...

There has got to be a cleaner way to do this...

I have this code here and it works but there has to be a better way.....i need two arrays that look like this [ { "Vector Arena - Auckland Central, New Zealand" => { "2010-10-10" => [ "Enter Sandman", "Unforgiven", "And justice for all" ] } }, { "Brisbane Entertainment Centre - Brisbane Qld, Aus...

How do I generate a listing of article names and e-mail addresses from pubmed results?

I want to generate a listing of (1) article titles and (2) article author e-mail addresses all from pubmed search results. Using the pubmed EFetch ultility (see this link for details: http://www.ncbi.nlm.nih.gov/corehtml/query/static/efetchlit_help.html) I have successfully created a php script to retrieve this data in an xml format as ...

C# Determing whether any element in a string array contains a given string anywhere

I have a string array: string[] Animals = {"Cat", "Dog", "Fish"}; I then want to determine which element contains the sequence "is" and return that entire element; in this case "fish" If I want to find "gh", it does not exist in the list, so it should return the first element, in this case "Cat" I've tried this linq code, but i don'...

PHP Two-Dimensional Associative Array Implode

I'd like to store the following array in a single text field in a mySQL table: $user_rating[0] = array('percent' => 'XXXXXXXXXXXXXXXXX', 'category' => 'Category 1', 'description' => 'XXXXXXXXXXXXXXXXX', 'link' => 'XXXXXXXXXXXXXXXXX', 'thumbnail' => 'XXXXXX...

Why am I getting a segmentation fault?

Hey guys I'm trying to write a program that takes in a plaintext file as it's argument and parses through it, adding all the numbers together and then print out the sum. The following is my code: #include <stdio.h> #include <stdlib.h> #include <ctype.h> static int sumNumbers(char filename[]) { int sum = 0; FILE *file = fopen(fi...

Java: How to do double-checked-locking with an array element?

This is what my code currently looks like: private boolean[] isInitialized = new boolean[COUNT]; private void ensureInitialized(int i) { if (! isInitialized[i]) { initialize(i); isInitialized[i] = true; } } Now I want to have it thread-safe. I know that double-checked-locking in Java is "teh 3vilness!!1", but ...

Ruby: Array contained in Array, any order

Suppose I have the following Ruby code: array_1 = ['a', 'b'] array_2 = ['a', 'b', 'c'] some_function(array_1, array_2) # => True some_function(array_2, array_1) # => False some_function(['a', 'b'], ['a', 'd']) # => False some_function(['x', 'y'], array_2) # => False I am pretty much looking for some_function to return True when Param...

Appending a string to an array

I have to write a function that prepends if boolean is true or append if boolean is false a string to an array. I'm not exactly sure what this means? Do I just add a string to the first element of the array if I'm prepending or add a string to the last element of the array if I'm appending? Or what? ...

check whether array contains false?

How to check the array true_or_false containing a value of false? bool[] true_or_false = new bool[10]; for (int i = 0; i < txtbox_and_message.Length; i++) { bool bStatus = true; if (txtbox_and_message[i] == "") { bStatus = false; } true_or_false[i] = bStatus; } ...

Java Resizing an Array

I want to write a function that resizes a 2D array to the given parameters. Its a general resize array: public static int[][] resize(int[][] source, int newWidth, int newHeight) { int[][] newImage=new int[newWidth][newHeight]; double scale=newWidth/source.length; for (int j=0;j<newHeight;j++) for (in...

Javascript Array Issue

ok, so when i do array=array2 then change something in array2 it changes array. how do i prevent this? ...

Difference in ways of deleting object array

Is there some difference in the following deletions of object array? The first way: MyClass **obj = new MyClass*[NUM]; for (int i=0; i<NUM; i++) obj[i] = new MyClass(val); obj[0]->method(); for (int i=0; i<NUM; i++) delete obj[i]; /// Deletion1 delete obj; /// Deletion1 The second way: MyClass **obj = ne...

converting string into multidimensional array

hi, I'd like to convert this string: $credit_packages_string = "300,0.25|1000,0.24|3000,0.22|4000,0.20|5000,0.18|6000,0.16|7000,0.14"; into this array: $credit_packages = array( array( 'credit_amount'=> 300, 'price_per_credit'=>0.25), array( 'credit_amount'=> 1000, 'price_per_credit'=>0.24), array( 'credit...

Java Scanner() to read from Array

Hi, I know you can set the input for a scanner in Java. Is it possible to feed an array to the scanner? ...

Implode and Explode Multi dimensional arrays

Are there any functions for recursively exploding and imploding multi-dimensional arrays in PHP? ...

PHP Callback function not working on object functions

I have an array and want to apply MySQLi->real_escape_string on every member of the array through array_walk but this is not working: array_walk($array, '$mysqli->real_escape_string'); It gives this error: Warning: array_walk() expects parameter 2 to be a valid callback, function '$mysqli->real_escape_string' not found or invalid ...