Search Results

Search found 17068 results on 683 pages for 'merge array'.

Page 16/683 | < Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | 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

  • Generate a merge statement from table structure

    - by Nigel Rivett
    This code generates a merge statement joining on he natural key and checking all other columns to see if they have changed. The full version deals with type 2 processing and an audit trail but this version is useful. Just the insert or update part is handy too. Change the table at the top (spt_values in master in the version) and the join columns for the merge in @nk. The output generated is at the top and the code to run to generate it below. Output merge spt_values a using spt_values b on a.name = b.name and a.number = b.number and a.type = b.type when matched and (1=0 or (a.low b.low) or (a.low is null and b.low is not null) or (a.low is not null and b.low is null) or (a.high b.high) or (a.high is null and b.high is not null) or (a.high is not null and b.high is null) or (a.status b.status) or (a.status is null and b.status is not null) or (a.status is not null and b.status is null) ) then update set low = b.low , high = b.high , status = b.status when not matched by target then insert ( name , number , type , low , high , status ) values ( b.name , b.number , b.type , b.low , b.high , b.status ); Generator set nocount on declare @t varchar(128) = 'spt_values' declare @i int = 0 -- this is the natural key on the table used for the merge statement join declare @nk table (ColName varchar(128)) insert @nk select 'Number' insert @nk select 'Name' insert @nk select 'Type' declare @cols table (seq int, nkseq int, type int, colname varchar(128)) ;with cte as ( select ordinal_position, type = case when columnproperty(object_id(@t), COLUMN_NAME,'IsIdentity') = 1 then 3 when nk.ColName is not null then 1 else 0 end, COLUMN_NAME from information_schema.columns c left join @nk nk on c.column_name = nk.ColName where table_name = @t ) insert @cols (seq, nkseq, type, colname) select ordinal_position, row_number() over (partition by type order by ordinal_position) , type, COLUMN_NAME from cte declare @result table (i int, j int, k int, data varchar(500)) select @i = @i + 1 insert @result (i, data) select @i, 'merge ' + @t + ' a' select @i = @i + 1 insert @result (i, data) select @i, ' using cte b' select @i = @i + 1 insert @result (i, j, data) select @i, nkseq, ' ' + case when nkseq = 1 then 'on' else 'and' end + ' a.' + ColName + ' = b.' + ColName from @cols where type = 1 select @i = @i + 1 insert @result (i, data) select @i, ' when matched and (1=0' select @i = @i + 1 insert @result (i, j, k, data) select @i, seq, 1, ' or (a.' + ColName + ' b.' + ColName + ')' + ' or (a.' + ColName + ' is null and b.' + ColName + ' is not null)' + ' or (a.' + ColName + ' is not null and b.' + ColName + ' is null)' from @cols where type 1 select @i = @i + 1 insert @result (i, data) select @i, ' )' select @i = @i + 1 insert @result (i, data) select @i, ' then update set' select @i = @i + 1 insert @result (i, j, data) select @i, nkseq, ' ' + case when nkseq = 1 then ' ' else ', ' end + colname + ' = b.' + colname from @cols where type = 0 select @i = @i + 1 insert @result (i, data) select @i, ' when not matched by target then insert' select @i = @i + 1 insert @result (i, data) select @i, ' (' select @i = @i + 1 insert @result (i, j, data) select @i, seq, ' ' + case when seq = 1 then ' ' else ', ' end + colname from @cols where type 3 select @i = @i + 1 insert @result (i, data) select @i, ' )' select @i = @i + 1 insert @result (i, data) select @i, ' values' select @i = @i + 1 insert @result (i, data) select @i, ' (' select @i = @i + 1 insert @result (i, j, data) select @i, seq, ' ' + case when seq = 1 then ' ' else ', ' end + 'b.' + colname from @cols where type 3 select @i = @i + 1 insert @result (i, data) select @i, ' );' select data from @result order by i,j,k,data

    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

  • Changing Word mail merge data source locations in bulk?

    - by Daft Viking
    I've just moved a number of Word mail merge files, and a number of Excel spreadsheets that are the data sources for the mail merges, from a Windows XP computer to a Windows 7 computer, and now all the paths for the merge sources are incorrect (used to be c:\documents and settings\user\my documents.... now c:\users\documents....). While I can correct the path of the data source in each file individually, I was hoping that there would be some way of updating the files in bulk, as there are a relatively large number of them. Word 2007 is what is being used, but the documents are all in the previous DOC format (not DOCX).

    Read the article

  • Changing Word mail merge data source locations in bulk?

    - by Daft Viking
    I've just moved a number of Word mail merge files, and a number of Excel spreadsheets that are the data sources for the mail merges, from a Windows XP computer to a Windows 7 computer, and now all the paths for the merge sources are incorrect (used to be c:\documents and settings\user\my documents.... now c:\users\documents....). While I can correct the path of the data source in each file individually, I was hoping that there would be some way of updating the files in bulk, as there are a relatively large number of them. Word 2007 is what is being used, but the documents are all in the previous DOC format (not DOCX).

    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

  • PHP multi dimensional array manipulation

    - by atif089
    Hi, This is my array Array ( [0] => Array ( [sample_id] => 3 [time] => 2010-05-30 21:11:47 ) [1] => Array ( [sample_id] => 2 [time] => 2010-05-30 21:11:47 ) [2] => Array ( [sample_id] => 1 [time] => 2010-05-30 21:11:47 ) ) And I want to get all the sample_ids in one array. can someone please help ? Can this be done without for loops (because arrays are very large).

    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

  • SSIS Basics: Using the Merge Join Transformation

    SSIS is able to take sorted data from more than one OLE DB data source and merge them into one table which can then be sent to an OLE DB destination. This 'Merge Join' transformation works in a similar way to a SQL join by specifying a 'join key' relationship. this transformation can save a great deal of processing on the destination. Annette Allen, as usual, gives clear guidance on how to do it.

    Read the article

  • SSIS Basics: Using the Merge Join Transformation

    SSIS is able to take sorted data from more than one OLE DB data source and merge them into one table which can then be sent to an OLE DB destination. This 'Merge Join' transformation works in a similar way to a SQL join by specifying a 'join key' relationship. this transformation can save a great deal of processing on the destination. Annette Allen, as usual, gives clear guidance on how to do it.

    Read the article

< Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >