arrays

Can this code be used with an array of custom objects?

[[NSUserDefaults standardUserDefaults] setObject:myArray forKey:@"myArray"]; If I make an array of custom objects conform to the NSCoding protocol, then does the above work? Do I have to make both the custom class and the view controller that holds the array of custom objects conform to the NSCoding protocol or just the custom class? D...

Is it ok to return a locally initialised array, if no how can I do it?

Take this example: public class foo { public int[] func() { int arr[] = new int[3]; // here initialised the array return arr; } } I'm not experienced with Java, but I know a little of C/C++. ...

How do I load this array into memory

I saved an array using the following code: NSData *data = [NSKeyedArchiver archivedDataWithRootObject:myArray]; [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"myArray"]; What is the code to load it back into memory? ...

Do I need to use NSKeyedArchiver?

I have an object. It has only two NSStrings as properties. I created an array to hold several of these objects. Do I need to use NSKeyedArchiver to save this array to disk, or can I just use NSUserDefaults? ...

Array writeToFile

Let's say I create an object like this: Person: NSString *name; NSString *phone; NSString *address I create several of these objects. Then I create an NSMutableArray called people and store them in there. Can I save this array to disk with Array writeToFile? Does it need to be converted to NSData? ...

Javascript - Pop a value from array, but not at the end of array

Hi. I have for example this array (each number is singolar, no one duplicate) called pvalue : 1 2 3 15 20 12 14 18 7 8 (sizeof 10). I need for example to pop the value "15", and after this pvalue should be 1 2 3 20 12 14 18 7 8 (sizeof 9). How can do it? the pop() function take the value at the end of the array. I don't want this :) ch...

how does the retweet mechanism work on twitter?

I'm creating similar thing to twitter retweet function! This is my database table for tweets (status messages): ID || USER_ID || TWEET || RETWEET_ID || RETWEET_NAME || DATE What I'm trying to find out is, if the logged in user retweets something, when they refresh the page I don't want them to see the retweet button (because obvious...

What pitfalls does this Perl code have?

I have written some code to print formatted arrays (first line = no of inputs, second line = max width of numbers). The star can be any sort of marker to differentiate some elements from the rest. $ cat inp.txt 6 2 1 * 2 3 4 9 12 * $ cat inp.txt | ./formatmyarray.pl ____ ____ ____ ____ ____ ____ | * | | | | | * | | 1 | ...

Error passing C array as char* function parameter

I'm trying to make a simple code in c language (Stupid question, but I'm learning), I dont understand that this code gives me an error ... I must be doing wrong, I can not know that I have to change...sorry for my English ... thanks in advance to all #include <stdio.h> #include <ctype.h> char* to_up(char* str_); int main() { cha...

PHP: Accessing array variables

Can someone help me access this array please I'm having trouble with indexes. array(10) { [0]=>array(2) { ["t"]=>array(1) { ["tag"]=>string(3) "php" } [0]=>array(1) { ["NumOccurrances"]=>string(1) "2" } } [1]=>array(2) { ["t"]=>array(1) { ["tag"]=>st...

Create a JavaScript array containing 1...N

Hi there, I'm looking for any alternatives to the below for creating a JavaScript array containing 1 through to N where N is only known at runtime. var foo = []; for (var i = 1; i <= N; i++) { foo.push(i); } To me it feels like there should be a way of doing this without the loop. Cheers for any ideas. ...

C#: Split a string (or user input) into individual characters withOUT using an array?

Ok here's what im trying to do. The user is prompted to enter an 8 digit number (7 numbers plus a hyphen 781-0432 I want it to break it apart and store it into 8 separate char variables without using an array: a = 7 b = 8 c = 1 ... h = 2 Ive been trying to do it with the Console.Read() method: a = Console.Read(); b = Console.Read();...

How would you serialize a large array with 10^9 values?

This throws an out of memory exception when using 10^8 items but not with 10^7. How would you serialize an array with 10^9 values in it so that it could be stored in a database? Dim List((10 ^ 9) - 1) As Int64 For i = 1 To (10 ^ 9) List(i - 1) = i Next Dim Format As New Runtime.Serialization.Formatters.Binary.BinaryFormatter Dim Wr...

What is wrong with my array syntax?

So I'm having a problem with arrays: print_r($_POST['bank']); produces the following output: Array ( ['deposit'] => 30 ) However, assert($_POST['bank']['deposit']==30); which immediately follows print_r, fails. I feel like an idiot, but could someone help me out? Since nothing is changing the value of $_POST, I suppose my syntax...

Javascript Arrays - Specify Key

Is it possible to create a javascript array similar to PHP's method which allows you to define the keys during creation? $arr = array("foo" => "bar", 12 => true); Or can this only be done like: myArray["foo"] = "bar"; myArray[12] = true; ...

How can I chomp an array in ruby?

Ok this is not a biggier but in the interest of writing cleaner code? IO.popen("Generate a list of files").readlines.each{|f_nl| f=f_nl.chomp # ... } Namely is there someway to chomp the whole array in one fell swoop? ...

How to return array in C++?

Why does the following code not work? It compiles fine but output is something like an address if I write f using * and the output is 0 if I write f without *. #include <iostream> #include<cstring> using namespace std; using std::size_t; int *f(size_t s){ int *ret=new int[s]; for (size_t a=0;a<s;a++) ret[a]=a; ...

Linq to mess up order of an array?

Update: False alarm! The source of the error was elsewhere. (See at the end of the question.) Is it possible that either Linq or foreach can mess up the order of an array? One of my testers reported to have experienced that the order of a list of items he fed in as input didn't match the order of the final list that was saved in the da...

Reload table/array with function?

Hi I have this code, what am I doing wrong? I have a function which I call playing a number of strings into an array. Then at some point I want to reload it after the user has edited the strings. This is the function: NSMutableArray *lessonsFunc(id a, id b, id c, id d, id e, id f){ monData *mon = [monData sharedData]; return [...

Linq Query If Field Is In An Array?

The code below is incorrect but the idea here is that I want to grab values from "SqlTable" where the value for "Field" is inside of "Array[]". var Result = from a in SqlTable where a.Field is in Array[] select a; ...