Search Results

Search found 16413 results on 657 pages for 'array manipulation'.

Page 12/657 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • Trimming byte array when converting byte array to string in Java/Scala

    - by prosseek
    Using ByteBuffer, I can convert a string into byte array: val x = ByteBuffer.allocate(10).put("Hello".getBytes()).array() > Array[Byte] = Array(104, 101, 108, 108, 111, 0, 0, 0, 0, 0) When converting the byte array into string, I can use new String(x). However, the string becomes hello?????, and I need to trim down the byte array before converting it into string. How can I do that? I use this code to trim down the zeros, but I wonder if there is simpler way. def byteArrayToString(x: Array[Byte]) = { val loc = x.indexOf(0) if (-1 == loc) new String(x) else if (0 == loc) "" else new String(x.slice(0,loc)) }

    Read the article

  • php Checking if value exists in array of array

    - by Mark
    I have an array within an array. $a = array ( 0 => array ( 'value' => 'America', ), 1 => array ( 'value' => 'England', ), ) How do I check if 'America' exists in the array? The America array could be any key, and there could be any number of subarrays, so a generalized solution please. Looking on the php manual I see in_array, but that only works for the top layer. so something like in_array("America", $a) would not work. Thanks.

    Read the article

  • array_key_exists is not working

    - by Arun
    array_key_exists is not working for large multidimensional array. For ex $arr=array( '1'=>10, '2'=>array('21'=>21, '22'=>22, '23'=>array('test'=>100, '231'=>231), ), '3'=>30, '4'=>40 ); array_key_exists('test',$arr) returns 'false' but it works with some simple arrays.

    Read the article

  • php mysql query strings array

    - by Chocho
    i am building a string that i check in mysql db. eg: formFields[] is an array - input1 is: string1 array_push(strings, formFields) 1st string and mysql query looks like this: "select * from my table where id in (strings)" formFields[] is an array - input2 is: string1, string2 array_push(strings, formFields) 2nd string and mysql query looks like this: "select * from my table where id in (strings)" formFields[] is an array - input3 is: string1, string2,string3 array_push(strings, formFields) 3rd string and mysql query looks like this: "select * from my table where id in (strings)" i will like to add single quotes and a comma to the array so that i have this for the array strings: "select * from my table where id in ('string1', 'string2','string3')" i tried using array implode, but still no luck any ideas? thanks

    Read the article

  • Flatten a PHP array

    - by deadkarma
    Say I have a form with these fields, and cannot rename them: <input type="text" name="foo[bar]" /> <input type="text" name="foo[baz]" /> <input type="text" name="foo[bat][faz]" /> When submitted, PHP turns this into an array: Array ( [foo] => Array ( [bar] => foo bar [baz] => foo baz [bat] => Array ( [faz] => foo bat faz ) ) ) What methods are there to convert or flatten this array into a data structure such as: Array ( [foo[bar]] => foo bar [foo[baz]] => foo baz [foo[bat][faz]] => foo bat faz )

    Read the article

  • Inserting only unique values into an array

    - by karl
    I have a set of values that I'm pushing into an array in the order they occur $valsArray = array(); //I process each value from a file (code removed for simplicity) //and then add into the array $valsArray[] = $val; How do I turn this into an associative array instead where the value gets inserted (as $key of associative array) only if it doesn't exist. If it does exist increment its count ($value of associative array) by 1. I'm trying to find a more efficient way of handling those values compared to what I'm doing now.

    Read the article

  • Passing array into constructor to use on JList

    - by OVERTONE
    I know the title sound confusing and thats because it is. its a bit long so try too stay with me. this is the layout i have my code designed variables constructor methods. im trying too fill a Jlist full on names. i want too get those names using a method. so here goes. in my variables i have my JList. its called contactNames; i also have an array which stores 5 strings which are the contacts names; heres the code for that anyway String contact1; String contact2; String contact3; String contact4; String contact5; String[] contactListNames; JList contactList; simple enough. then in my constructor i have the Jlist defined to fill itself with the contents of the array fillContactList(); JList contactList = new JList(contactListNames); that method fillContactList() is coming up shortly. notice i dont have the array defined in the constructor. so heres my first question. can i do that? define the array to contain something in te constructor rather than filling it fromt the array. now heres where stuff gets balls up. ive created three different methods all of which havent worked. basically im trying to fill the array with all of them. this is the simplest one. it doesnt set the Jlist, it doesnt do anything compilicated. all it trys too do is fill the array one bit at a time public void fillContactList() { for(int i = 0;i<3;i++) { try { String contact; System.out.println(" please fill the list at index "+ i); Scanner in = new Scanner(System.in); contact = in.next(); contactListNames[i] = contact; in.nextLine(); } catch(Exception e) { e.printStackTrace(); } } } unfortunately this doesnt qwork. i get the print out to fill it at index 0; i input something and i get a nice big stack trace starting at contactListNames[i] = contact; so my two questions in short are how i define an array in a constructor. and why cant i fill the array from that method. ************************888 **************************888 stack trace by request please fill the list at index 0 overtone java.lang.NullPointerException please fill the list at index 1 at project.AdminMessages.fillContactList(AdminMessages.java:408) at project.AdminMessages.<init>(AdminMessages.java:88) at project.AdminUser.createAdminMessages(AdminUser.java:32) at project.AdminUser.<init>(AdminUser.java:18) at project.AdminUser.main(AdminUser.java:47) it was a null poiinter exception

    Read the article

  • Fill a array with List data with one more element

    - by marionmaiden
    Hello, By a question that I made, I figured out that tho copy elements from one list to an array I just need to use the method toArray() for this. But let's suppose I have a List with n objects. I want to copy then into a array sized n+1 and add into the first position another object and in the other n positions the n data of the list. This is the way I'm doing it for now, but I'm just wondering if there is a better way for do that: Object array[] = new Object[list.size() + 1]; Object chk = new Object(); array[0] = chk; for(int i = 1; i < array.length; i++){ array[i] = list.get(i); }

    Read the article

  • Array Sorting Question for News System

    - by lemonpole
    Hello all. I'm currently stuck trying to figure out how to sort my array files. I have a simple news posting system that stores the content in seperate .dat files and then stores them in an array. I numbered the files so that my array can sort them from lowest number to greatest; however, I have run into a small problem. To begin here is some more information on my system so that you can understand it better. The function that gathers my files is: function getNewsList() { $fileList = array(); // Open the actual directory if($handle = opendir(ABSPATH . ADMIN . "data")) { // Read all file from the actual directory while($file = readdir($handle)) { if(!is_dir($file)) { $fileList[] = $file; } } } // Return the array. return $fileList; } On a seperate file is the programming that processes the news post. I didn't post that code for simplicity's sake but I will explain how the files are named. The files are numbered and the part of the post's title is used... for the numbering I get a count of the array and add "1" as an offset. I get the title of the post, encode it to make it file-name-friendly and limit the amount of text so by the end of it all I end up with: // Make the variable that names the file that will contain // the post. $filename = "00{$newnumrows}_{$snipEncode}"; When running print_r on the above function I get: Array ( [0] => 0010_Mira_mi_Soledad.dat [1] => 0011_WOah.dat [2] => 0012_Sinep.dat [3] => 0013_Living_in_Warfa.dat [4] => 0014_Hello.dat [5] => 001_AS.dat [6] => 002_ASASA.dat [7] => 003_SSASAS.dat ... [13] => 009_ASADADASADAFDAF.dat ) And this is how my content is displayed. For some reason according to the array sorting 0010 comes before 001...? Is there a way I can get my array to sort 001 before 0010?

    Read the article

  • JQuery make an array - how/what is best

    - by russp
    I have 4 serailized arrays that I want to pass to php for processing. What is the best way to combine them into a single array example: serial_1 = $('#col1').sortable('serialize'); serial_2 = $('#col2').sortable('serialize'); serial_3 = $('#col3').sortable('serialize'); serial_4 = $('#col4').sortable('serialize');` each serialized array relates to a column/section of the page (col1,col2 etc.) What I need to do/would like to do is create a single array that puts the serialized array inside another array for a single post. example: var new_array = serilaize(col_1(serial_1),col2(serial_2),col3,(serial_3),col4(serial_4)) I KNOW THAT IS NOT RIGHT as I have no idea in JQuery how to right the correct syntax. This new array is to be posted via ajax like this: $.ajax({ url: "test.php", type: "post", data: new_array, error: function(){ alert('SOME ERROR MESSAGE'); } }); Thanks in advance

    Read the article

  • sort associative array PHP

    - by jim smith
    Here's my array, how do I sort it by saleref? Array ( [xml] => Array ( [sale] => Array ( [0] => Array ( [saleref] => 12345 [saleline] => 1 [product] => producta [date] => 19/ 3/10 [manifest] => 0 [qty] => 1 [nextday] => [order_status] => ) [1] => Array ( [saleref] => 12344 [saleline] => 1 [product] => productb [date] => 18/ 3/10 [manifest] => 11892 [qty] => 1 [nextday] => [order_status] => )

    Read the article

  • iPhone tableview: titleForHeaderInSection derived from array

    - by Nic Hubbard
    I have a tableview that is populated by an array. Currently the tableview has no grouping. What I would like to do is check a value of each array object, such as State, and group all the CA items together, all the OR items together, etc. Then, assign those groups a title. The array is dynamic, and will grow and get new values in the future, so I can't hardcode titles, I would like these to somehow come from my initial array. Currently I am using the following, but it does not take into account sorting of the array, or if I removed all of the items in the array that have to do with California. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if (section == 0) { return @"California"; } else if (section == 1) { return @"Washington"; } else { return @"Utah"; } }//end tableView So, I am confusing myself as to how this would be possible. Any tips would be appreciated.

    Read the article

  • How does array class work in Java?

    - by oks16
    In Java, array is a class and extends Object. I am curious to know about this special array class. I don't find the class definition anywhere. Doing a getClass().getName() gives strange result. String[] array = new String[]{"one","two"}; System.out.println(array.getClass().getName()); // prints [Ljava.lang.String; I want to understand how array works under the hood. Is the array class definition hardcoded in the JVM? Any resources, books, links on this will be helpful. Thank you.

    Read the article

  • Creating a 2d matrix from an array (java)

    - by anna
    I'm supposed to write a method that creates a 2d matrix from an array, for instance: ({1, 2, 3, 4}, 3) should return the matrix {{1, 2, 3}, {4}} public class Matrix { public static int[][]toM(int[] array, int a) { int[][]matrix = new int [(array.length + a- 1)/ a][a]; for (int i = 0; i < array.length; i++){ int value = array[i]; value = value++; for (int row = 0; row < (array.length + a- 1)/a; row++) { for (int col = 0; col < a; col++) { matrix[row][col]= value++; } } } return matrix; } } I'm getting [[4, 5, 6], [7, 8, 9]]?

    Read the article

  • clear php empty array

    - by redcoder
    i have the following array and want to get rid/remove the empty array and rearrange it in an order.can anyone help me please. Array ( [ufile] => Array ( [name] => Array ( [0] => chicken soup.jpg [1] => [2] => hot n sour sup.jpg [3] => [4] => [5] => [6] => [7] => [8] => ) [type] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => ) [tmp_name] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => ) [error] => Array ( [0] => 1 [1] => 4 [2] => 1 [3] => 4 [4] => 4 [5] => 4 [6] => 4 [7] => 4 [8] => 4 ) [size] => Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 [6] => 0 [7] => 0 [8] => 0 ) ) )

    Read the article

  • javascript - Google Chrome cluttering Array generated from .split()

    - by patrick
    Given the following string: var str = "one,two,three"; If I split the string on the commas, I normally get an array, as expected: var arr = str.split(/\s*,\s*/); Trouble is that in Google Chrome (for Mac), it appends extra properties to the array. Output from Chrome's debugger: arr: Array 0: one 1: two 2: three constructor: function Array() index: undefined input: undefined length: 3 So if I iterate over the array with a for/in loop, it iterates over the new properties. Specifically the input and index properties. Using hasOwnProperty doesn't seem to help. A fix would be to do a for loop based on the length of the Array. Still I'm wondering if anyone has insight into why Chrome behaves this way. Firefox and Safari don't have this issue.

    Read the article

  • Merging arrays, adding array as dimension to existing array

    - by JohnDoe
    Lets say i have 2 arrays Array1 array($info) $info['id'] => some id $info['text'] => some text etc lets say i have a function that returns another array called images Array 2 array($images) $images[0] => some link 1 $images[1] => some link 2 etc How do i add $images to the $info array as a new dimension, as such $info['image'][0] => some link 1 $info['image'][1] => some link 2

    Read the article

  • in_array() - help on what specifically would return true

    - by Kerri
    I am using in_array, and I'm trying to use it in a way where it will only return true if it's an exact match of one of the objects in the array, not just if it's "in" the array. e.g. 1. $sample_array = array('123', '234', '345'); 2. $sample_array = array('23', '34', '45'); in_array('23', $sample_array); In the above example, I would only want version 2 to return true, because it has the exact string, '23'. Version 1 returns true as well though, because the array contains instances of the string '23'. How would I get this to work so that only version 2 returns true? Am I even using the right function?

    Read the article

  • Excel formula - sometimes array formula, sometimes not

    - by Jonas
    I want to write some data to an Excel file, and I want the first page to show a summary of the data that are spread all over the sheets. The individual data items on a sheet can be included or excluded, and I want the summary to be calculated only on the included values. Thus, I thought I'd use a formula like this to show, for example, an average (for which empty fields shouldn't be counted, either): =AVERAGE(IF('dataSheet1'!$B:$B=1,IF('dataSheet1'!$I:$I<>"",'dataSheet1'!$I:$I,""),"")) If I have this formula in dataSheet1, everything works fine. If I have this formula in the summary sheet, I need to enter it as an array formula, and I have to specify the exact ranges to make it work. Is there a way (aside from adding the average in dataSheet, and then referencing the result in summary) to make the formula work without having it turn into an array formula?

    Read the article

  • PHP - Counting matching arrays in array

    - by Sergio
    hi there, I have an array structure that looks like this: Array ( [0] => Array ( [type] => image [data] => Array ( [id] => 1 [alias] => test [caption] => no caption [width] => 200 [height] => 200 ) ) [1] => Array ( [type] => image [data] => Array ( [id] => 2 [alias] => test2 [caption] => hello there [width] => 150 [height] => 150 ) ) ) My question is, how can I get a count of the number of embedded arrays that have their type set as image (or anything else for that matter)? In practise this value can vary. So, the above array would give me an answer of 2. Thanks

    Read the article

  • 2 dimensional array

    - by ankit
    we have these arrays.... $cities = array("nagpur","kanpur","delhi","chd","Noida","mumbai","nagpur"); $names = array("munish","imteyaz","ram","shyam","ankit","Rahul","mohan"); now i want a 2 dimensional array with name of city as key and all the corresponding names as its values. <?php $cities = array("nagpur","kanpur","nagpur","delhi","kanpur"); $names = array("ankit","atul","aman","amit","manu"); foreach ($cities as $i => $value) { echo "\n"; echo $value; $city=$value; $k=0; foreach ($cities as $ii => $m) { If($city==$m) { echo$names[$ii] ; $final[$i][$k]=$names[$ii]; $arr = array($city => array($k =>$names[$ii] )); $k++; } } echo"\n<tr></tr>"; } wat i tried is this.but it doesnt work.help me

    Read the article

  • Unable to access value of nested array element

    - by John Conde
    I'm having an issue getting the value of a nested array element. Here's what I've got: print_r($environment); // Outputs Array ( [0] => Array ( ['parameter'] => Vibration ['conditions'] => 204 ['method'] => D ) [1] => Array ( ['parameter'] => Immersion ['conditions'] => 104 ['method'] => B ) [2] => Array ( ['parameter'] => Shock ['conditions'] => 213 ['method'] => I ) [3] => Array ( ['parameter'] => Humidity ['conditions'] => 106 ['method'] => - ) ) print_r($environment[0]); // Outputs Array ( ['parameter'] => Vibration ['conditions'] => 204 ['method'] => D ) echo $environment[0]['parameter']; // Nothing Maybe I've been looking at this for too long. Any ideas would be greatly appreciated.

    Read the article

  • In .NET, What Is Fastest Way to Initialize Multi-Dimensional Array to Non-Default Value

    - by AMissico
    How do I initialize a multi-dimensional array of a primitive type as fast as possible? I am stuck with using multi-dimensional arrays. My problem is performance. The following routine initializes a 100x100 array in approx. 500 ticks. Removing the int.MaxValue initialization results in approx. 180 ticks just for the looping. Approximately 100 ticks to create the array without looping and without initializing to int.MaxValue. Routines similiar to this are called a few tens-of-thousands to several million times. I am open to suggestions on how to optimize this non-default initialization of an array. One idea I had is to use a smaller primitive type when available. For instance, using byte instead of int, saves 100 ticks. I would be happy with this, but I am hoping that I don't have to change the primitive data type. public int[,] CreateArray(Size size) { int[,] array = new int[size.Width, size.Height]; for (int x = 0; x < size.Width; x++) { for (int y = 0; y < size.Height; y++) { array[x, y] = int.MaxValue; } } return array; }

    Read the article

  • php - replace array elements with another array's elements?

    - by Simpson88Keys
    Not sure how to go about this... But, I have two arrays, one with updated information, another with outdated information... There are a lot more elements in the second array, but I'm looking to "update" the outdated one with the updated information. Here's what the arrays look like: //Outdated Array ( [0] => Array ( [anum] => 3236468462 [cid] => 4899097762 [mid] => 1104881401 [na_title] => [na_fname] => JOHN [m_initial] => [na_lname] => DOE [na_suffix] => [na_addr1] => 1234 SAMPLE AVENUE [na_addr2] => [na_city] => NORWALK [state] => OH [zip] => [zip_plus_4] => [route] => R002 [dma_code] => 510334 ) ) //Updated Array ( [1] => Array ( [0] => YUD990 [1] => 98 [2] => 1234 Sample Avenue [3] => [4] => Norwalk [5] => OH [6] => 44857-9215 [7] => 3236468462 ) ) To clarify, I want to: (1) Match up the value for [7] from the updated array with the value for [anum] in the outdated array, and then update [na_addr1], [na_addr2], [na_city], [state], [zip], [zip_plus_4] in the outdated array with the values for [2],[3],[4],[5],[6] (I know I'll need to split the updated [6] in order to get it to map corrected to the outdated) Feel like I'm making this very confusing... sorry about that...

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >